Skip to content

Commit 13fe7b0

Browse files
committed
remove default value for raise_on_upcast
1 parent b8d6d8c commit 13fe7b0

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

pandas/core/internals/blocks.py

Lines changed: 6 additions & 6 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, raise_on_upcast: bool = False) -> Block:
431+
def coerce_to_target_dtype(self, other, raise_on_upcast: bool) -> Block:
432432
"""
433433
coerce the current block to a dtype compat for other
434434
we will return a block, possibly object, and not raise
@@ -713,7 +713,7 @@ def replace(
713713
if value is None or value is NA:
714714
blk = self.astype(np.dtype(object))
715715
else:
716-
blk = self.coerce_to_target_dtype(value)
716+
blk = self.coerce_to_target_dtype(value, raise_on_upcast=False)
717717
return blk.replace(
718718
to_replace=to_replace,
719719
value=value,
@@ -1237,7 +1237,7 @@ def where(self, other, cond) -> list[Block]:
12371237
if self.ndim == 1 or self.shape[0] == 1:
12381238
# no need to split columns
12391239

1240-
block = self.coerce_to_target_dtype(other)
1240+
block = self.coerce_to_target_dtype(other, raise_on_upcast=False)
12411241
return block.where(orig_other, cond)
12421242

12431243
else:
@@ -1431,7 +1431,7 @@ def shift(self, periods: int, fill_value: Any = None) -> list[Block]:
14311431
fill_value,
14321432
)
14331433
except LossySetitemError:
1434-
nb = self.coerce_to_target_dtype(fill_value)
1434+
nb = self.coerce_to_target_dtype(fill_value, raise_on_upcast=False)
14351435
return nb.shift(periods, fill_value=fill_value)
14361436

14371437
else:
@@ -1669,13 +1669,13 @@ def where(self, other, cond) -> list[Block]:
16691669
if self.ndim == 1 or self.shape[0] == 1:
16701670
if isinstance(self.dtype, IntervalDtype):
16711671
# TestSetitemFloatIntervalWithIntIntervalValues
1672-
blk = self.coerce_to_target_dtype(orig_other)
1672+
blk = self.coerce_to_target_dtype(orig_other, raise_on_upcast=False)
16731673
return blk.where(orig_other, orig_cond)
16741674

16751675
elif isinstance(self, NDArrayBackedExtensionBlock):
16761676
# NB: not (yet) the same as
16771677
# isinstance(values, NDArrayBackedExtensionArray)
1678-
blk = self.coerce_to_target_dtype(orig_other)
1678+
blk = self.coerce_to_target_dtype(orig_other, raise_on_upcast=False)
16791679
return blk.where(orig_other, orig_cond)
16801680

16811681
else:

web/pandas/pdeps/0006-ban-upcasting.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PDEP-6: Ban upcasting in setitem-like operations
22

33
- Created: 23 December 2022
4-
- Status: Accepted
4+
- Status: Implemented
55
- Discussion: [#39584](https://github.com/pandas-dev/pandas/pull/50402)
66
- Author: [Marco Gorelli](https://github.com/MarcoGorelli) ([original issue](https://github.com/pandas-dev/pandas/issues/39584) by [Joris Van den Bossche](https://github.com/jorisvandenbossche))
77
- Revision: 1
@@ -244,3 +244,4 @@ Deprecate sometime in the 2.x releases (after 2.0.0 has already been released),
244244
### PDEP History
245245

246246
- 23 December 2022: Initial draft
247+
- 4 July 2024: Change status to "implemented"

0 commit comments

Comments
 (0)