Skip to content

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

Merged
merged 17 commits into from
Sep 6, 2020
Merged

BUG: Respect errors="ignore" during extension astype #35979

merged 17 commits into from
Sep 6, 2020

Conversation

dsaxton
Copy link
Member

@dsaxton dsaxton commented Aug 29, 2020

@dsaxton dsaxton added Bug Dtype Conversions Unexpected or buggy dtype conversions ExtensionArray Extending pandas with custom dtypes or arrays. labels Aug 29, 2020
@dsaxton dsaxton added this to the 1.1.2 milestone Aug 29, 2020
# TODO: Should we try/except this astype?
values = self.values.astype(dtype)
try:
values = self.values.astype(dtype)
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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

@pep8speaks
Copy link

pep8speaks commented Aug 30, 2020

Hello @dsaxton! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-09-06 00:58:13 UTC

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok fine on the change for backport (ex some comments), but can you create an issue to add this keyword to the EA signature?

@@ -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

Copy link
Contributor

Choose a reason for hiding this comment

The 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'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so for all, can add those here

[
Series(["x", "y", "z"], dtype="string"),
Series(["x", "y", "z"], dtype="category"),
Series(3 * [Timestamp("2020-01-01")]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a tz to be an EA

@jreback jreback merged commit 9228066 into pandas-dev:master Sep 6, 2020
@jreback
Copy link
Contributor

jreback commented Sep 6, 2020

thanks @dsaxton

@simonjayhawkins
Copy link
Member

@meeseeksdev backport 1.1.x

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Sep 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants