-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: RangeIndex.astype('category') #41263
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
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
|
||
import pandas as pd | ||
from pandas import ( | ||
CategoricalDtype, | ||
CategoricalIndex, | ||
Float64Index, | ||
Index, | ||
Int64Index, | ||
|
@@ -533,3 +535,24 @@ def test_isin_range(self, base): | |
result = base.isin(values) | ||
expected = np.array([True, False]) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("copy", [True, False]) | ||
@pytest.mark.parametrize("name", [None, "foo"]) | ||
@pytest.mark.parametrize("ordered", [True, False]) | ||
def test_astype_category(self, copy, name, ordered, simple_index): | ||
super().test_astype_category(copy, name, ordered, simple_index) | ||
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. hmm we don't usually call the super functions as they are already called so this is confusing. i think you can remove. (assume my assertion is true) |
||
|
||
# GH 41263 | ||
idx = simple_index if not name else simple_index.rename(name) | ||
|
||
dtypes = [CategoricalDtype(ordered=ordered)] | ||
if ordered is False: | ||
# dtype='category' defaults to ordered=False, so only test once | ||
dtypes.append("category") | ||
|
||
for dtype in dtypes: | ||
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. can you not simply construct the expected result and use 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. Yeah, that's better. It however exposed a bug because I fixed that bug in |
||
# standard categories | ||
result = idx.astype(dtype, copy=copy) | ||
assert isinstance(result, CategoricalIndex) | ||
assert isinstance(result.categories, RangeIndex) | ||
assert (result.categories == idx).all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe have a test explicitly for RangeIndex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests.indexes.ranges.test_range.py::TestRangeIndex
inherits from this base class, so it's tested that way. Do you have something else in mind?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tm.assert_foo functions dont raise when we assert an Int64Index equals a RangeIndex. So off the top my head it isn't obvious that this edited test would fail in master. im asking for a test that is super-obviously tied to this bugfix