Skip to content

Commit 7a3b6fe

Browse files
committed
GH 30975-Fix for Series.append(DataFrame)
1 parent 4ed9a39 commit 7a3b6fe

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pandas/core/series.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,6 +2538,9 @@ def append(self, to_append, ignore_index=False, verify_integrity=False) -> "Seri
25382538
to_concat = [self]
25392539
to_concat.extend(to_append)
25402540
else:
2541+
if not isinstance(to_append, type(self)):
2542+
msg = f"to_append should be a Series or list/tuple of Series, got {type(to_append)}"
2543+
raise TypeError(msg)
25412544
to_concat = [self, to_append]
25422545
return self._ensure_type(
25432546
concat(

pandas/tests/series/methods/test_append.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ def test_append_tuples(self):
6161

6262
tm.assert_series_equal(expected, result)
6363

64+
def test_append_dataframe(self):
65+
# GH 30975
66+
df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
67+
df2 = pd.DataFrame({"C": [5, 6], "D": [7, 8]})
68+
69+
expected = pd.Series(pd.concat([df.A, df2.D]))
70+
result = df.A.append(df2.D)
71+
72+
tm.assert_series_equal(expected, result)
6473

6574
class TestSeriesAppendWithDatetimeIndex:
6675
def test_append(self):

0 commit comments

Comments
 (0)