Skip to content

BUG: Index with object dtype and negative loc for insert adding none and replacing existing value #44545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 21, 2021

Conversation

phofl
Copy link
Member

@phofl phofl commented Nov 20, 2021

This behaves like np.insert, so changed the docstring. Making this compatible with list.insert would be a breaking change

Nevertheless the else block in the base implementation had a bug, so fixed that one too

@phofl phofl added Index Related to the Index class or subclasses Bug labels Nov 20, 2021
# GH#44509
idx = Index(["1", "2", "3"])
result = idx.insert(loc, val)
expected = Index(["1", "2", val, "3"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check that type(expected[2]) is type(val); numpy often messes that up with dt64/td64

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numpy/numpy#12550 i dont know exactly what conditions it shows up in, but i get nervous whenever np.datetime64 or np.timedelta64 objects get near an object-dtype ndarray

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the reference

@mroeschke mroeschke added this to the 1.4 milestone Nov 21, 2021
@jreback jreback merged commit 8f1dd29 into pandas-dev:master Nov 21, 2021
@jreback
Copy link
Contributor

jreback commented Nov 21, 2021

thanks @phofl

@phofl phofl deleted the 44509 branch November 22, 2021 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Index Related to the Index class or subclasses
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: pd.DataFrame.columns.insert( -1: <name>) does not insert in last position
4 participants