Skip to content

Commit f0d5c82

Browse files
fix fillna limit case + update tests for no longer raising
1 parent 961b924 commit f0d5c82

File tree

3 files changed

+3
-14
lines changed

3 files changed

+3
-14
lines changed

pandas/core/internals/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ def fillna(
13371337
return [self.copy(deep=False)]
13381338

13391339
if limit is not None:
1340-
mask[mask.cumsum(self.ndim - 1) > limit] = False
1340+
mask[mask.cumsum(self.values.ndim - 1) > limit] = False
13411341

13421342
if inplace:
13431343
nbs = self.putmask(mask.T, value)
@@ -1857,7 +1857,7 @@ def fillna(
18571857
) -> list[Block]:
18581858
if isinstance(self.dtype, (IntervalDtype, StringDtype)):
18591859
# Block.fillna handles coercion (test_fillna_interval)
1860-
if limit is not None:
1860+
if isinstance(self.dtype, IntervalDtype) and limit is not None:
18611861
raise ValueError("limit must be None")
18621862
return super().fillna(
18631863
value=value,

pandas/tests/frame/indexing/test_where.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,15 +1025,9 @@ def test_where_producing_ea_cond_for_np_dtype():
10251025
@pytest.mark.parametrize(
10261026
"replacement", [0.001, True, "snake", None, datetime(2022, 5, 4)]
10271027
)
1028-
def test_where_int_overflow(replacement, using_infer_string):
1028+
def test_where_int_overflow(replacement):
10291029
# GH 31687
10301030
df = DataFrame([[1.0, 2e25, "nine"], [np.nan, 0.1, None]])
1031-
if using_infer_string and replacement not in (None, "snake"):
1032-
with pytest.raises(
1033-
TypeError, match=f"Invalid value '{replacement}' for dtype 'str'"
1034-
):
1035-
df.where(pd.notnull(df), replacement)
1036-
return
10371031
result = df.where(pd.notnull(df), replacement)
10381032
expected = DataFrame([[1.0, 2e25, "nine"], [replacement, 0.1, replacement]])
10391033

pandas/tests/series/indexing/test_setitem.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,6 @@ def test_series_where(self, obj, key, expected, raises, val, is_inplace):
839839
obj = obj.copy()
840840
arr = obj._values
841841

842-
if raises and obj.dtype == "string":
843-
with pytest.raises(TypeError, match="Invalid value"):
844-
obj.where(~mask, val)
845-
return
846-
847842
res = obj.where(~mask, val)
848843

849844
if val is NA and res.dtype == object:

0 commit comments

Comments
 (0)