Skip to content

Commit f0fa390

Browse files
fix fillna upcast issue
1 parent bc7c82f commit f0fa390

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

pandas/core/internals/blocks.py

Lines changed: 3 additions & 1 deletion
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,6 +1688,8 @@ 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:
1692+
orig_cond = orig_cond[:, None]
16911693
return blk.where(orig_other, orig_cond)
16921694

16931695
elif isinstance(self, NDArrayBackedExtensionBlock):

pandas/tests/frame/methods/test_fillna.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ def test_fillna_mixed_type(self, float_string_frame, using_infer_string):
7474
).all()
7575
assert (result.loc[result.index[5:20], "foo"] == "bar").all()
7676

77-
if using_infer_string:
78-
with pytest.raises(TypeError, match="Invalid value"):
79-
mf.fillna(value=0)
80-
81-
mf["foo"] = mf["foo"].astype("object")
8277
result = mf.fillna(value=0)
8378
assert (result.loc[result.index[-10:], "A"] == 0).all()
8479
assert (result.loc[result.index[5:20], "foo"] == 0).all()

0 commit comments

Comments
 (0)