Skip to content

Commit ef9b938

Browse files
authored
BUG: Fix bug when concatenating Index of strings (#33436)
1 parent 40fd73a commit ef9b938

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/whatsnew/v1.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ Strings
440440
^^^^^^^
441441

442442
- Bug in the :meth:`~Series.astype` method when converting "string" dtype data to nullable integer dtype (:issue:`32450`).
443-
-
443+
- Bug in :meth:`Series.str.cat` returning ``NaN`` output when other had :class:`Index` type (:issue:`33425`)
444444

445445

446446
Interval

pandas/core/strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,7 @@ def _get_series_list(self, others):
22972297
if isinstance(others, ABCSeries):
22982298
return [others]
22992299
elif isinstance(others, ABCIndexClass):
2300-
return [Series(others._values, index=others)]
2300+
return [Series(others._values, index=idx)]
23012301
elif isinstance(others, ABCDataFrame):
23022302
return [others[x] for x in others]
23032303
elif isinstance(others, np.ndarray) and others.ndim == 2:

pandas/tests/test_strings.py

+9
Original file line numberDiff line numberDiff line change
@@ -3624,3 +3624,12 @@ def test_string_array_extract():
36243624

36253625
result = result.astype(object)
36263626
tm.assert_equal(result, expected)
3627+
3628+
3629+
@pytest.mark.parametrize("klass", [tuple, list, np.array, pd.Series, pd.Index])
3630+
def test_cat_different_classes(klass):
3631+
# https://github.com/pandas-dev/pandas/issues/33425
3632+
s = pd.Series(["a", "b", "c"])
3633+
result = s.str.cat(klass(["x", "y", "z"]))
3634+
expected = pd.Series(["ax", "by", "cz"])
3635+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)