Skip to content

BUG: NumericIndex.insert does not preserve dtype #43921

Closed
@jbrockmendel

Description

@jbrockmendel

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd

idx = pd.NumericIndex([1.0, 2.0, 3.0] dtype='int32')
result = idx.insert(1, 4.0)

assert result.dtype == idx.dtype  # <- nope!


### Issue Description

cc @topper-123 

### Expected Behavior

Should preserve type and dtype

### Installed Versions

<details>

Replace this line with the output of pd.show_versions()

</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsIndexRelated to the Index class or subclasses

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions