Skip to content

Commit d003e6e

Browse files
committed
update warn to raise
1 parent aedaf59 commit d003e6e

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

pandas/core/internals/blocks.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def split_and_operate(self, func, *args, **kwargs) -> list[Block]:
428428
# Up/Down-casting
429429

430430
@final
431-
def coerce_to_target_dtype(self, other, warn_on_upcast: bool = False) -> Block:
431+
def coerce_to_target_dtype(self, other, raise_on_upcast: bool = False) -> Block:
432432
"""
433433
coerce the current block to a dtype compat for other
434434
we will return a block, possibly object, and not raise
@@ -455,17 +455,17 @@ def coerce_to_target_dtype(self, other, warn_on_upcast: bool = False) -> Block:
455455
isinstance(other, (np.datetime64, np.timedelta64)) and np.isnat(other)
456456
)
457457
):
458-
warn_on_upcast = False
458+
raise_on_upcast = False
459459
elif (
460460
isinstance(other, np.ndarray)
461461
and other.ndim == 1
462462
and is_integer_dtype(self.values.dtype)
463463
and is_float_dtype(other.dtype)
464464
and lib.has_only_ints_or_nan(other)
465465
):
466-
warn_on_upcast = False
466+
raise_on_upcast = False
467467

468-
if warn_on_upcast:
468+
if raise_on_upcast:
469469
raise TypeError(f"Invalid value '{other}' for dtype '{self.values.dtype}'")
470470
if self.values.dtype == new_dtype:
471471
raise AssertionError(
@@ -1098,7 +1098,7 @@ def setitem(self, indexer, value) -> Block:
10981098
casted = np_can_hold_element(values.dtype, value)
10991099
except LossySetitemError:
11001100
# current dtype cannot store value, coerce to common dtype
1101-
nb = self.coerce_to_target_dtype(value, warn_on_upcast=True)
1101+
nb = self.coerce_to_target_dtype(value, raise_on_upcast=True)
11021102
return nb.setitem(indexer, value)
11031103
else:
11041104
if self.dtype == _dtype_obj:
@@ -1169,7 +1169,7 @@ def putmask(self, mask, new) -> list[Block]:
11691169
if not is_list_like(new):
11701170
# using just new[indexer] can't save us the need to cast
11711171
return self.coerce_to_target_dtype(
1172-
new, warn_on_upcast=True
1172+
new, raise_on_upcast=True
11731173
).putmask(mask, new)
11741174
else:
11751175
indexer = mask.nonzero()[0]
@@ -1630,11 +1630,11 @@ def setitem(self, indexer, value):
16301630
except (ValueError, TypeError):
16311631
if isinstance(self.dtype, IntervalDtype):
16321632
# see TestSetitemFloatIntervalWithIntIntervalValues
1633-
nb = self.coerce_to_target_dtype(orig_value, warn_on_upcast=True)
1633+
nb = self.coerce_to_target_dtype(orig_value, raise_on_upcast=True)
16341634
return nb.setitem(orig_indexer, orig_value)
16351635

16361636
elif isinstance(self, NDArrayBackedExtensionBlock):
1637-
nb = self.coerce_to_target_dtype(orig_value, warn_on_upcast=True)
1637+
nb = self.coerce_to_target_dtype(orig_value, raise_on_upcast=True)
16381638
return nb.setitem(orig_indexer, orig_value)
16391639

16401640
else:
@@ -1730,13 +1730,13 @@ def putmask(self, mask, new) -> list[Block]:
17301730
if isinstance(self.dtype, IntervalDtype):
17311731
# Discussion about what we want to support in the general
17321732
# case GH#39584
1733-
blk = self.coerce_to_target_dtype(orig_new, warn_on_upcast=True)
1733+
blk = self.coerce_to_target_dtype(orig_new, raise_on_upcast=True)
17341734
return blk.putmask(orig_mask, orig_new)
17351735

17361736
elif isinstance(self, NDArrayBackedExtensionBlock):
17371737
# NB: not (yet) the same as
17381738
# isinstance(values, NDArrayBackedExtensionArray)
1739-
blk = self.coerce_to_target_dtype(orig_new, warn_on_upcast=True)
1739+
blk = self.coerce_to_target_dtype(orig_new, raise_on_upcast=True)
17401740
return blk.putmask(orig_mask, orig_new)
17411741

17421742
else:

pandas/tests/frame/indexing/test_indexing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,6 @@ def test_add_new_column_infer_string():
18861886

18871887
class TestSetitemValidation:
18881888
# This is adapted from pandas/tests/arrays/masked/test_indexing.py
1889-
# but checks for warnings instead of errors.
18901889
def _check_setitem_invalid(self, df, invalid, indexer):
18911890
orig_df = df.copy()
18921891

pandas/tests/series/indexing/test_indexing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ def test_setitem_dict_and_set_disallowed_multiindex(self, key):
432432

433433
class TestSetitemValidation:
434434
# This is adapted from pandas/tests/arrays/masked/test_indexing.py
435-
# but checks for warnings instead of errors.
436435
def _check_setitem_invalid(self, ser, invalid, indexer):
437436
orig_ser = ser.copy()
438437

0 commit comments

Comments
 (0)