-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix StringArray.astype for category dtype #40450
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 2 commits
03b8b47
333e24b
c29c9dd
0c7bc59
3777066
94a8b58
f71afa2
d8ff716
c0f007d
57727df
857d2e2
98747f4
21c55d6
d9bb52d
61a7d81
b93d628
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 |
---|---|---|
|
@@ -470,6 +470,18 @@ def test_astype_categories_raises(self): | |
with pytest.raises(TypeError, match="got an unexpected"): | ||
s.astype("category", categories=["a", "b"], ordered=True) | ||
|
||
def test_astype_str_to_extension_dtype(self): | ||
# GH-40351 | ||
s = Series(["A", np.NaN], dtype="string") | ||
result = s.astype("category") | ||
expected = Series(["A", np.NaN], dtype="category") | ||
tm.assert_series_equal(result, expected) | ||
|
||
s = Series(["1/1/2021", "2/1/2021"], dtype="string") | ||
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 u add an example for Timedelta, Datetime w/time zone and Interval (all the EA types) 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 added test for all ExtensionArray dtypes. |
||
result = s.astype("period[M]") | ||
expected = Series(["1/1/2021", "2/1/2021"], dtype="period[M]") | ||
tm.assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("items", [["a", "b", "c", "a"], [1, 2, 3, 1]]) | ||
def test_astype_from_categorical(self, items): | ||
ser = Series(items) | ||
|
Uh oh!
There was an error while loading. Please reload this page.