Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/source/whatsnew/v1.0.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Bug fixes

- Using ``pd.NA`` with :meth:`DataFrame.to_json` now correctly outputs a null value instead of an empty object (:issue:`31615`)

**Strings**

- Using ``pd.NA`` with :meth:`Series.str.repeat` now correctly outputs a null value instead of raising error for vector inputs (:issue:`31632`)

.. ---------------------------------------------------------------------------

.. _whatsnew_102.contributors:
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ def scalar_rep(x):
else:

def rep(x, r):
if x is libmissing.NA:
return x
try:
return bytes.__mul__(x, r)
except TypeError:
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,18 @@ def test_repeat(self):
assert isinstance(rs, Series)
tm.assert_series_equal(rs, xp)

def test_repeat_with_null(self):
# GH: 31632
values = Series(["a", None], dtype="string")
result = values.str.repeat([3, 4])
exp = Series(["aaa", None], dtype="string")
tm.assert_series_equal(result, exp)

values = Series(["a", "b"], dtype="string")
result = values.str.repeat([3, None])
exp = Series(["aaa", None], dtype="string")
tm.assert_series_equal(result, exp)

def test_match(self):
# New match behavior introduced in 0.13
values = Series(["fooBAD__barBAD", np.nan, "foo"])
Expand Down