-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG: Fix Series doesn't work in pd.astype(). Now treat Series as dict. #16725
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 1 commit
2351a2e
37fc561
930c479
342871c
ce7e131
0280e5c
7d88920
08eabd9
fbd0755
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
dtype is_dict_like is true, use get() instead of `values()…
…` in `pd.Series.astype`
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -494,6 +494,13 @@ def test_astype_dict_like(self, dtype_class): | |
| assert_frame_equal(df, equiv) | ||
| assert_frame_equal(df, original) | ||
|
|
||
| # if dtypes provided is empty, the resulting DataFrame | ||
| # should be the same as the original DataFrame | ||
| dt7 = dtype_class({}) | ||
|
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. add issue number as a comment |
||
| equiv = df.astype(dt7) | ||
| assert_frame_equal(df, equiv) | ||
| assert_frame_equal(df, original) | ||
|
|
||
| def test_astype_duplicate_col(self): | ||
| a1 = Series([1, 2, 3, 4, 5], name='a') | ||
| b = Series([0.1, 0.2, 0.4, 0.6, 0.8], name='b') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,6 +176,11 @@ def test_astype_dict_like(self, dtype_class): | |
| with pytest.raises(KeyError): | ||
| s.astype(dt4) | ||
|
|
||
| # if dtypes provided is empty, it should error | ||
| dt5 = dtype_class({}) | ||
|
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 very sure about the desired behavior here. Should we return the |
||
| with pytest.raises(KeyError): | ||
| s.astype(dt5) | ||
|
|
||
| def test_astype_generic_timestamp_deprecated(self): | ||
| # see gh-15524 | ||
| data = [1] | ||
|
|
||
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.
new_type = dtype[self.name]is ok here now