-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix str dtype -> IntegerDtype conversions #43949
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
Conversation
dd0d90f
to
cc12100
Compare
Looks like all 8 failures are the same issue in essence. I'll wait for advice on how to fix that. |
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.
need to remove the changes from is_string itself. you can infer inside the integer constructor though.
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.
pls add tests from each of the issues
@jreback Thanks for reviewing. I'll have a look at your comments and see what I can do. Where do tests specific to issues go? |
Okay, I think I've addressed the above issues and this solution is better. All tests should be passing now too. I just need to write tests specifically for the two issues this is closing (please point me to where they should go). Note, I'm no longer dealing with #15585, as your comment hinted I shouldn't. Edit: Looks like all tests passed but the macOS one spuriously gave |
046efad
to
db03121
Compare
i think I was trying to target too much in this PR. I'm only going to target #25472 now, which the PR in its current state definitely solves. Just not sue of the best way to write a unit test for that issue. Advice appreciated (or someone can feel free just to do it and push). |
bcd4fec
to
815e185
Compare
pandas/core/arrays/integer.py
Outdated
if inferred_type in ("string", "unicode"): | ||
# casts from str are always safe since they raise | ||
# a ValueError if the str cannot be parsed into an int | ||
return values.astype(dtype, copy=copy) |
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.
what happens if you dont put this special case here and do the astype on L135? itd be nice to not add the inferred_type arg here
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.
@jbrockmendel I agree it would be nice not to have that arg there, but nor do I think it's too much of a problem, since this function is only used in one other place (as far as I can tell). If I remove this special case and let L135 always do the cast, it fails because a str -> nullable int cast is technically unsafe (though not really, I think, as per my comment). However, removing casting="safe"
from L135 would create all sorts of other problems.
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.
so the issue i have with this is actually passing the inferred keyword, simply use this instead before L240 and would be better.
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.
or i think check values.dtype instead of inferred_type?
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.
@jreback Done.
@jbrockmendel I suppose we can change to that if need be, but I'd already tried @jreback's change, so if that works...
@jreback @jbrockmendel Incorporated / replied to your feedback. Hopefully everything is good to go now. |
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.
cc @jbrockmendel if comments
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.
LGTM
thanks @alexreg very nice! |
@jreback No problem. Thanks both of you for the reviews and getting this merged. |
closes #25472