-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Respect errors="ignore" during extension astype #35979
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 10 commits
d234627
5bc2ba5
c84a9c6
85bd7f2
73d0ee0
dbc3a76
fc6538f
7efb4ba
a0f2f9b
e66bde4
c16204b
3813c96
de8091b
234cfe1
d07b565
88635de
61b6eb8
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
CategoricalDtype, | ||
DataFrame, | ||
DatetimeTZDtype, | ||
Interval, | ||
IntervalDtype, | ||
NaT, | ||
Series, | ||
|
@@ -565,3 +566,18 @@ def test_astype_empty_dtype_dict(self): | |
result = df.astype(dict()) | ||
tm.assert_frame_equal(result, df) | ||
assert result is not df | ||
|
||
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. do we have tests for these same types for errors='raise' (the default) and errors='coerce'? 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 don't think so for all, can add those here |
||
@pytest.mark.parametrize( | ||
"values", | ||
[ | ||
Series(["x", "y", "z"], dtype="string"), | ||
Series(["x", "y", "z"], dtype="category"), | ||
Series(3 * [Timestamp("2020-01-01")]), | ||
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 needs a tz to be an EA |
||
Series(3 * [Interval(0, 1)]), | ||
], | ||
) | ||
def test_astype_ignores_errors_for_extension_dtypes(self, values): | ||
# https://github.com/pandas-dev/pandas/issues/35471 | ||
expected = DataFrame(values) | ||
result = expected.astype(float, errors="ignore") | ||
tm.assert_frame_equal(result, expected) |
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.
instead of this
add in this keyword to the EA astype
it's a little more code (as likely you need to refactor into an _astype method
but better i think
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.
I can add this, although it becomes a lot more code. I was able to pull a tiny bit into a helper function, but mostly each method seems to have its own idiosyncrasies that makes it hard to abstract away details. This became quite messy so let me know if I should revert and maybe leave as a follow-up enhancement.
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.
hmm, Changing the signature on the base extension array is an api change. I'm not so sure if this is a good idea since this only fixes pandas EAs and third party EAs that have overridden astype will need to update their code to support this.
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.
It seems too large of a change for a bug fix, went ahead and reverted