Skip to content

Commit 94179cd

Browse files
authored
CLN/TST: delegate StringArray.fillna() to parent class + add tests (#37987)
1 parent 71bf9fa commit 94179cd

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

pandas/core/arrays/string_.py

-4
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,6 @@ def __setitem__(self, key, value):
282282

283283
super().__setitem__(key, value)
284284

285-
def fillna(self, value=None, method=None, limit=None):
286-
# TODO: validate dtype
287-
return super().fillna(value, method, limit)
288-
289285
def astype(self, dtype, copy=True):
290286
dtype = pandas_dtype(dtype)
291287
if isinstance(dtype, StringDtype):

pandas/tests/arrays/string_/test_string.py

+18
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,24 @@ def test_reduce_missing(skipna, dtype):
422422
assert pd.isna(result)
423423

424424

425+
def test_fillna_args():
426+
# GH 37987
427+
428+
arr = pd.array(["a", pd.NA], dtype="string")
429+
430+
res = arr.fillna(value="b")
431+
expected = pd.array(["a", "b"], dtype="string")
432+
tm.assert_extension_array_equal(res, expected)
433+
434+
res = arr.fillna(value=np.str_("b"))
435+
expected = pd.array(["a", "b"], dtype="string")
436+
tm.assert_extension_array_equal(res, expected)
437+
438+
msg = "Cannot set non-string value '1' into a StringArray."
439+
with pytest.raises(ValueError, match=msg):
440+
arr.fillna(value=1)
441+
442+
425443
@td.skip_if_no("pyarrow", min_version="0.15.0")
426444
def test_arrow_array(dtype):
427445
# protocol added in 0.15.0

0 commit comments

Comments
 (0)