Skip to content

Commit de665d6

Browse files
prakhar987SeeminSyed
authored andcommitted
BUG: string methods with NA (pandas-dev#31684)
1 parent 8ec31f6 commit de665d6

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

doc/source/whatsnew/v1.0.2.rst

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ Bug fixes
8585
- Fixed bug where :meth:`GroupBy.first` and :meth:`GroupBy.last` would raise a ``TypeError`` when groups contained ``pd.NA`` in a column of object dtype (:issue:`32123`)
8686
- Fix bug in :meth:`Series.convert_dtypes` for series with mix of integers and strings (:issue:`32117`)
8787

88+
**Strings**
89+
90+
- Using ``pd.NA`` with :meth:`Series.str.repeat` now correctly outputs a null value instead of raising error for vector inputs (:issue:`31632`)
91+
8892
.. ---------------------------------------------------------------------------
8993
9094
.. _whatsnew_102.contributors:

pandas/core/strings.py

+2
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ def scalar_rep(x):
775775
else:
776776

777777
def rep(x, r):
778+
if x is libmissing.NA:
779+
return x
778780
try:
779781
return bytes.__mul__(x, r)
780782
except TypeError:

pandas/tests/test_strings.py

+12
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,18 @@ def test_repeat(self):
11571157
assert isinstance(rs, Series)
11581158
tm.assert_series_equal(rs, xp)
11591159

1160+
def test_repeat_with_null(self):
1161+
# GH: 31632
1162+
values = Series(["a", None], dtype="string")
1163+
result = values.str.repeat([3, 4])
1164+
exp = Series(["aaa", None], dtype="string")
1165+
tm.assert_series_equal(result, exp)
1166+
1167+
values = Series(["a", "b"], dtype="string")
1168+
result = values.str.repeat([3, None])
1169+
exp = Series(["aaa", None], dtype="string")
1170+
tm.assert_series_equal(result, exp)
1171+
11601172
def test_match(self):
11611173
# New match behavior introduced in 0.13
11621174
values = Series(["fooBAD__barBAD", np.nan, "foo"])

0 commit comments

Comments
 (0)