Skip to content

Commit

Permalink
fix reshaping of condition in where - only do for 2d blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Nov 15, 2024
1 parent e156770 commit f21004b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ def where(self, other, cond) -> list[Block]:
-------
List[Block]
"""
# assert cond.ndim == self.ndim
assert cond.ndim == self.ndim
assert not isinstance(other, (ABCIndex, ABCSeries, ABCDataFrame))

transpose = self.ndim == 2
Expand Down Expand Up @@ -1688,7 +1688,12 @@ def where(self, other, cond) -> list[Block]:
if isinstance(self.dtype, (IntervalDtype, StringDtype)):
# TestSetitemFloatIntervalWithIntIntervalValues
blk = self.coerce_to_target_dtype(orig_other, raise_on_upcast=False)
if isinstance(orig_cond, np.ndarray) and orig_cond.ndim == 1:
if (
self.ndim == 2
and isinstance(orig_cond, np.ndarray)
and orig_cond.ndim == 1
and not is_1d_only_ea_dtype(blk.dtype)
):
orig_cond = orig_cond[:, None]
return blk.where(orig_other, orig_cond)

Expand Down

0 comments on commit f21004b

Please sign in to comment.