-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
REGR: fillna on f32 column raising for f64 #43455
Conversation
pandas/core/dtypes/cast.py
Outdated
if tipo.kind not in ["f", "i", "u"]: | ||
# Anything other than float/integer we cannot hold | ||
return False | ||
elif dtype.itemsize < tipo.itemsize: |
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.
should the itemsize only be compared if dtype.kind and tipo.kind are the same? i.e. tipo.kind is also 'f'. How is the itemsize of an int or uint relevant?
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.
Thanks for bringing this up. I think it ultimately comes down to -> if can_hold_element
holds True, then using np.putmask
is assumed to be safe. So itemsize of int or uint matters because numpy
allows safe casting of i16 to f32 for example, but not i64 to f32.
But I think the itemsize check is not sufficient here, because numpy
won't putmask
int32
infloat32
. Maybe np.can_cast
should be used instead?
does this break any current tests? |
Think the failures are flaky |
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.
do you have a tests for the complex case? (e.g. you are closing the issue).
this looks ok to backport
Have changed the approach to be less invasive, so backport I think safer now. I think the EDIT: more reasoning for changing approach was not being able satisfactorily answer #43455 (comment) and other failing test cases I discovered that weren't handled by just the itemsize patch. The test now covers all numpy int/floating types |
lgtm. cc @jbrockmendel @phofl |
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 @mzeitlin11 |
@meeseeksdev backport 1.3.x |
Something went wrong ... Please have a look at my logs. |
…g for f64) (#43474) * Backport PR #43455: REGR: fillna on f32 column raising for f64 * Update pandas/tests/series/methods/test_fillna.py Co-authored-by: Matthew Zeitlin <[email protected]>
float32
dtype when using value arg #43424For now have put whatsnew in 1.3.3, but might be better for 1.4 since regression is later (worked in 1.1.5) and the
can_hold_element
change causes subtle indexing behavior differences (but that are now more consistent between int and float)