Skip to content

API: numeric inference in Series constructor #40489

Closed
@jbrockmendel

Description

@jbrockmendel

Index.__new__ does inference on numeric data more aggressively than Series.__new__. It would be nice if these behaviors matched. (xref #40451 also about differenced between Series vs Index inference, though in that case Series is more aggressive about inference)

data = np.array([np.nan, np.nan, 2.0], dtype=object)

>>> pd.Series(data).dtype
dtype('O')

>>> pd.Index(data).dtype
dtype('float64')

>>> pd.array(data).dtype
Float64Dtype()

(if we passed data[:-1] to pd.array we'd get back a PandasArray[object] bc it passes skipna=True to lib.infer_dtype)

Changing the Series behavior to match Index breaks 207 tests (140 of which are for the str accessor; i expect some others are false-positives), so this would be a non-trivial API change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API - ConsistencyInternal Consistency of API/BehaviorBugIndexRelated to the Index class or subclassesSeriesSeries data structure

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions