-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: fix Categorical.astype for dtype=np.int32 argument #39615
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
efbd0e1
c0da63c
8380e99
eb03c27
cbfe793
e8d9650
ebad911
fdf2d56
4bd1589
97c981f
e108f0d
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 |
---|---|---|
|
@@ -68,7 +68,7 @@ def test_astype_categorical_to_other(self): | |
exp = Series(["a", "b", "b", "a", "a", "c", "c", "c"]) | ||
tm.assert_series_equal(cat.astype("str"), exp) | ||
s2 = Series(Categorical(["1", "2", "3", "4"])) | ||
exp2 = Series([1, 2, 3, 4]).astype("int64") | ||
exp2 = Series([1, 2, 3, 4]).astype("int") | ||
tm.assert_series_equal(s2.astype("int"), exp2) | ||
|
||
# object don't sort correctly, so just compare that we have the same | ||
|
@@ -94,6 +94,14 @@ def cmp(a, b): | |
result = ser.astype("object").astype(CategoricalDtype()) | ||
tm.assert_series_equal(result, roundtrip_expected) | ||
|
||
def test_categorical_int_to_int32(self): | ||
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 parameterize on the any_int_dtype, ideally this also works on any_int_nullable_dtype (but not sure that will just work). 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. Done - created a new fixture |
||
# GH 39402 | ||
|
||
df = DataFrame(data={"col1": [2.0, -1.0, 3.0]}) | ||
df.col1 = df.col1.astype("category") | ||
df.col1 = df.col1.astype(np.int32) | ||
assert df.col1.dtype.type is np.int32 | ||
|
||
def test_series_to_categorical(self): | ||
# see gh-16524: test conversion of Series to Categorical | ||
series = Series(["a", "b", "c"]) | ||
|
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.
should be named test_categorical_astype_to_int
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.
Done