Skip to content

API/BUG/CLN: Index/Series common dtype handling #12758

Closed
@sinhrks

Description

@sinhrks

Code Sample, a copy-pastable example if possible

Some inconsistencies there.

# OK: specifying int dtype with float value coerces to int (same as numpy)
pd.Series([1, 2, 3.5], dtype=int)
#0    1
#1    2
#2    3
# dtype: int64

# OK
pd.Index(np.array([1, 2, 3.5], dtype=int))
# Int64Index([1, 2, 3], dtype='int64')

# NG: If list is given, dtype is ignored
pd.Index([1, 2, 3.5], dtype=int)
# Float64Index([1.0, 2.0, 3.5], dtype='float64')

Expected Output

  • All list-like input should be handled by a consistent logic.
  • If dtype is specified, the result must be the specified dtype. Otherwise raise.
    • To do this, merge base Index creation and Series sanitizing logic to use same ndarray dtype handling.

output of pd.show_versions()

Current master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions