Skip to content

Commit f21004b

Browse files
fix reshaping of condition in where - only do for 2d blocks
1 parent e156770 commit f21004b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pandas/core/internals/blocks.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ def where(self, other, cond) -> list[Block]:
12221222
-------
12231223
List[Block]
12241224
"""
1225-
# assert cond.ndim == self.ndim
1225+
assert cond.ndim == self.ndim
12261226
assert not isinstance(other, (ABCIndex, ABCSeries, ABCDataFrame))
12271227

12281228
transpose = self.ndim == 2
@@ -1688,7 +1688,12 @@ def where(self, other, cond) -> list[Block]:
16881688
if isinstance(self.dtype, (IntervalDtype, StringDtype)):
16891689
# TestSetitemFloatIntervalWithIntIntervalValues
16901690
blk = self.coerce_to_target_dtype(orig_other, raise_on_upcast=False)
1691-
if isinstance(orig_cond, np.ndarray) and orig_cond.ndim == 1:
1691+
if (
1692+
self.ndim == 2
1693+
and isinstance(orig_cond, np.ndarray)
1694+
and orig_cond.ndim == 1
1695+
and not is_1d_only_ea_dtype(blk.dtype)
1696+
):
16921697
orig_cond = orig_cond[:, None]
16931698
return blk.where(orig_other, orig_cond)
16941699

0 commit comments

Comments
 (0)