-
Notifications
You must be signed in to change notification settings - Fork 915
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
MAINT: Adapt to NumPy 2 promotion changes #16141
Changes from all commits
b1d7498
dd8ff3f
4d1bea5
dbd38ba
b125041
9e2f334
ddc91b7
d0dee3e
6af0dec
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 |
---|---|---|
|
@@ -301,15 +301,28 @@ def normalize_binop_value( | |
if isinstance(other, cudf.Scalar): | ||
if self.dtype == other.dtype: | ||
return other | ||
|
||
# expensive device-host transfer just to | ||
# adjust the dtype | ||
other = other.value | ||
|
||
# NumPy 2 needs a Python scalar to do weak promotion, but | ||
# pandas forces weak promotion always | ||
# TODO: We could use 0, 0.0, and 0j for promotion to avoid copies. | ||
if other.dtype.kind in "ifc": | ||
other = other.item() | ||
elif not isinstance(other, (int, float, complex)): | ||
# Go via NumPy to get the value | ||
other = np.array(other) | ||
if other.dtype.kind in "ifc": | ||
other = other.item() | ||
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. The biggest change, on NumPy 2, we need to pass Python scalars to align with Pandas (not NumPy, which pandas does not align with here). To get those Python scalars, |
||
|
||
# Try and match pandas and hence numpy. Deduce the common | ||
# dtype via the _value_ of other, and the dtype of self. TODO: | ||
# When NEP50 is accepted, this might want changed or | ||
# simplified. | ||
# This is not at all simple: | ||
# np.result_type(np.int64(0), np.uint8) | ||
# dtype via the _value_ of other, and the dtype of self on NumPy 1.x | ||
# with NumPy 2, we force weak promotion even for our/NumPy scalars | ||
# to match pandas 2.2. | ||
# Weak promotion is not at all simple: | ||
# np.result_type(0, np.uint8) | ||
# => np.uint8 | ||
# np.result_type(np.asarray([0], dtype=np.int64), np.uint8) | ||
# => np.int64 | ||
|
@@ -626,7 +639,9 @@ def can_cast_safely(self, to_dtype: DtypeObj) -> bool: | |
min_, max_ = iinfo.min, iinfo.max | ||
|
||
# best we can do is hope to catch it here and avoid compare | ||
if (self.min() >= min_) and (self.max() <= max_): | ||
# Use Python floats, which have precise comparison for float64. | ||
# NOTE(seberg): it would make sense to limit to the mantissa range. | ||
if (float(self.min()) >= min_) and (float(self.max()) <= max_): | ||
filled = self.fillna(0) | ||
return (cudf.Series(filled) % 1 == 0).all() | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -341,7 +341,6 @@ def test_dtype(in_dtype, expect): | |
np.complex128, | ||
complex, | ||
"S", | ||
"a", | ||
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. Just avoids an error |
||
"V", | ||
"float16", | ||
np.float16, | ||
|
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.
This just adds the
OverflowError
check, because NumPy is now strict, otherwise the error type would change here.