-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
CLEAN: Enforce pdep6 #59007
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
CLEAN: Enforce pdep6 #59007
Changes from 9 commits
45cafc2
c26dd1f
1b420c6
396e270
cfe700b
6784d79
aedaf59
d003e6e
e14281d
6671ead
b8d6d8c
13fe7b0
f7c057c
1fb058d
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 |
---|---|---|
|
@@ -428,7 +428,7 @@ def split_and_operate(self, func, *args, **kwargs) -> list[Block]: | |
# Up/Down-casting | ||
|
||
@final | ||
def coerce_to_target_dtype(self, other, warn_on_upcast: bool = False) -> Block: | ||
def coerce_to_target_dtype(self, other, raise_on_upcast: bool = False) -> Block: | ||
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. Are there any usages of this method, outside this file, that does not set this to 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. there's no usage of this method at all outside this file i've removed the default |
||
""" | ||
coerce the current block to a dtype compat for other | ||
we will return a block, possibly object, and not raise | ||
|
@@ -455,25 +455,18 @@ def coerce_to_target_dtype(self, other, warn_on_upcast: bool = False) -> Block: | |
isinstance(other, (np.datetime64, np.timedelta64)) and np.isnat(other) | ||
) | ||
): | ||
warn_on_upcast = False | ||
raise_on_upcast = False | ||
elif ( | ||
isinstance(other, np.ndarray) | ||
and other.ndim == 1 | ||
and is_integer_dtype(self.values.dtype) | ||
and is_float_dtype(other.dtype) | ||
and lib.has_only_ints_or_nan(other) | ||
): | ||
warn_on_upcast = False | ||
|
||
if warn_on_upcast: | ||
warnings.warn( | ||
f"Setting an item of incompatible dtype is deprecated " | ||
"and will raise an error in a future version of pandas. " | ||
f"Value '{other}' has dtype incompatible with {self.values.dtype}, " | ||
"please explicitly cast to a compatible dtype first.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
raise_on_upcast = False | ||
|
||
if raise_on_upcast: | ||
raise TypeError(f"Invalid value '{other}' for dtype '{self.values.dtype}'") | ||
if self.values.dtype == new_dtype: | ||
raise AssertionError( | ||
f"Did not expect new dtype {new_dtype} to equal self.dtype " | ||
|
@@ -1105,7 +1098,7 @@ def setitem(self, indexer, value) -> Block: | |
casted = np_can_hold_element(values.dtype, value) | ||
except LossySetitemError: | ||
# current dtype cannot store value, coerce to common dtype | ||
nb = self.coerce_to_target_dtype(value, warn_on_upcast=True) | ||
nb = self.coerce_to_target_dtype(value, raise_on_upcast=True) | ||
return nb.setitem(indexer, value) | ||
else: | ||
if self.dtype == _dtype_obj: | ||
|
@@ -1176,7 +1169,7 @@ def putmask(self, mask, new) -> list[Block]: | |
if not is_list_like(new): | ||
# using just new[indexer] can't save us the need to cast | ||
return self.coerce_to_target_dtype( | ||
new, warn_on_upcast=True | ||
new, raise_on_upcast=True | ||
).putmask(mask, new) | ||
else: | ||
indexer = mask.nonzero()[0] | ||
|
@@ -1637,11 +1630,11 @@ def setitem(self, indexer, value): | |
except (ValueError, TypeError): | ||
if isinstance(self.dtype, IntervalDtype): | ||
# see TestSetitemFloatIntervalWithIntIntervalValues | ||
nb = self.coerce_to_target_dtype(orig_value, warn_on_upcast=True) | ||
nb = self.coerce_to_target_dtype(orig_value, raise_on_upcast=True) | ||
return nb.setitem(orig_indexer, orig_value) | ||
|
||
elif isinstance(self, NDArrayBackedExtensionBlock): | ||
nb = self.coerce_to_target_dtype(orig_value, warn_on_upcast=True) | ||
nb = self.coerce_to_target_dtype(orig_value, raise_on_upcast=True) | ||
return nb.setitem(orig_indexer, orig_value) | ||
|
||
else: | ||
|
@@ -1737,13 +1730,13 @@ def putmask(self, mask, new) -> list[Block]: | |
if isinstance(self.dtype, IntervalDtype): | ||
# Discussion about what we want to support in the general | ||
# case GH#39584 | ||
blk = self.coerce_to_target_dtype(orig_new, warn_on_upcast=True) | ||
blk = self.coerce_to_target_dtype(orig_new, raise_on_upcast=True) | ||
return blk.putmask(orig_mask, orig_new) | ||
|
||
elif isinstance(self, NDArrayBackedExtensionBlock): | ||
# NB: not (yet) the same as | ||
# isinstance(values, NDArrayBackedExtensionArray) | ||
blk = self.coerce_to_target_dtype(orig_new, warn_on_upcast=True) | ||
blk = self.coerce_to_target_dtype(orig_new, raise_on_upcast=True) | ||
return blk.putmask(orig_mask, orig_new) | ||
|
||
else: | ||
|
Uh oh!
There was an error while loading. Please reload this page.