Skip to content

BUG: Preserve name in Index.astype #32036

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 39 commits into from
Mar 27, 2020
Merged

BUG: Preserve name in Index.astype #32036

merged 39 commits into from
Mar 27, 2020

Conversation

dsaxton
Copy link
Member

@dsaxton dsaxton commented Feb 16, 2020

from pandas import Index


@pytest.mark.parametrize(
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not very comprehensive. just hook into the current astype tests and check for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

there are llikely many more paths that are not exactly correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dsaxton this is the much more important point

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what's meant by the current astype tests since there are lots of them. Would extending the parameterization work for being more comprehensive?

Copy link
Contributor

Choose a reason for hiding this comment

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

no but i would rather simply add a check i. the current astype tests

there are many many cases and this doesn’t begin to cover

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a bad idea, was struggling with how to test this exhaustively when certain conversions won't even be possible

Copy link
Member

Choose a reason for hiding this comment

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

@dsaxton did you decide to stick with whats currently here, or have another approach in mind?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jbrockmendel I think I'll try your idea for these tests

Copy link
Member Author

Choose a reason for hiding this comment

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

With this approach I'm assuming we'd skip the MultiIndex cases in the indices fixture, since the name attribute isn't so interesting (we care about the names)? Those seem to be all the test failures.

Copy link
Member

Choose a reason for hiding this comment

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

that or check that the names are retained. If this isnt for just the base Index class, then it probably belongs in tests.indexes.test_common

@jreback jreback added the Dtype Conversions Unexpected or buggy dtype conversions label Feb 16, 2020
@pep8speaks
Copy link

pep8speaks commented Feb 23, 2020

Hello @dsaxton! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-03-26 15:32:09 UTC

@@ -337,3 +337,25 @@ def test_has_duplicates(self, indices):
idx = holder([indices[0]] * 5)
assert idx.is_unique is False
assert idx.has_duplicates is True

@pytest.mark.parametrize("dtype", ["int64", "uint64", "float64", "category"])
Copy link
Member

Choose a reason for hiding this comment

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

was this the one where adding more dtypes here led to 90k tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it's too many; added a couple more. Let me know if there are others you think I should include.

@dsaxton
Copy link
Member Author

dsaxton commented Mar 11, 2020

@dsaxton can you merge master to be on the safe side

LGTM

@jbrockmendel Looks like there's an unrelated CI failure, but probably just wait for that to be fixed?

@jbrockmendel
Copy link
Member

Yah, hopefully that will be fixed by #32630.

@dsaxton
Copy link
Member Author

dsaxton commented Mar 11, 2020

Yah, hopefully that will be fixed by #32630.

@jbrockmendel Green now, thanks for the review

@jbrockmendel
Copy link
Member

cc @jreback i think this is good to go

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

looks good, a comment, ping on green.

else:
indices.name = "idx"

try:
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment here on why you have this try/except

@jreback jreback added this to the 1.1 milestone Mar 17, 2020
@jreback
Copy link
Contributor

jreback commented Mar 17, 2020

@jbrockmendel if you have any more comments

@jbrockmendel
Copy link
Member

im a happy camper

@jreback
Copy link
Contributor

jreback commented Mar 22, 2020

lgtm. can you merge master, and ping on green (just to make sure it respects all of the recent merges)

@dsaxton
Copy link
Member Author

dsaxton commented Mar 22, 2020

lgtm. can you merge master, and ping on green (just to make sure it respects all of the recent merges)

@jreback Merged master + green

@jreback
Copy link
Contributor

jreback commented Mar 24, 2020

hmm somthing failing here, pls merge master and see

@dsaxton
Copy link
Member Author

dsaxton commented Mar 24, 2020

hmm somthing failing here, pls merge master and see

@jreback Looks like one of the fixtures may have changed, hopefully will be fixed now. I think the linting error will be fixed by #32987

@jreback jreback added the Bug label Mar 27, 2020
@jreback jreback merged commit e872067 into pandas-dev:master Mar 27, 2020
@jreback
Copy link
Contributor

jreback commented Mar 27, 2020

thanks @dsaxton

@dsaxton dsaxton deleted the astype-keep-name branch March 27, 2020 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pandas.index.copy remove index name information when specifying new dtype
4 participants