-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 4 commits
5209ebc
446e348
23230fc
9ca1401
8f23161
2471e5a
3959813
1ebe800
f2a24e6
01b326c
59b4960
b709d3d
b41b62b
e1ddf33
e9bb2fe
7fefe7f
1ee1b10
7e8f078
6152b21
0266f7e
b461674
81d1170
a55bf9e
045f364
82b2e41
6c0c76f
25a4086
0c62cff
1c9e219
1a2dd70
dfa141e
b81c90f
9352d33
95d2307
378ee31
2b82625
2b2fb84
50d580d
9a288ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
|
||
from pandas import Index | ||
|
||
|
||
@pytest.mark.parametrize( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are llikely many more paths that are not exactly correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dsaxton this is the much more important point There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jbrockmendel I think I'll try your idea for these tests There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
"from_type, to_type", [("float64", "int64"), ("int64", "float64")] | ||
) | ||
def test_astype_preserves_name(from_type, to_type): | ||
idx = Index([1, 2], name="abc", dtype=from_type).astype(to_type) | ||
|
||
assert idx.name == "abc" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"from_type, to_type", [("float64", "int64"), ("int64", "float64")] | ||
) | ||
def test_copy_with_astype_preserves_name(from_type, to_type): | ||
idx = Index([1, 2], name="abc", dtype=from_type).copy(dtype=to_type) | ||
|
||
assert idx.name == "abc" |
Uh oh!
There was an error while loading. Please reload this page.