Skip to content

Commit 8d1e084

Browse files
hvardhan20jreback
authored andcommitted
BUG: AssertionError on Series.append(DataFrame) fix #30975 (#31036)
1 parent 3b2c8f6 commit 8d1e084

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pandas/core/series.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,7 @@ def searchsorted(self, value, side="left", sorter=None):
24752475
# -------------------------------------------------------------------
24762476
# Combination
24772477

2478-
def append(self, to_append, ignore_index=False, verify_integrity=False) -> "Series":
2478+
def append(self, to_append, ignore_index=False, verify_integrity=False):
24792479
"""
24802480
Concatenate two or more Series.
24812481
@@ -2552,10 +2552,8 @@ def append(self, to_append, ignore_index=False, verify_integrity=False) -> "Seri
25522552
to_concat.extend(to_append)
25532553
else:
25542554
to_concat = [self, to_append]
2555-
return self._ensure_type(
2556-
concat(
2557-
to_concat, ignore_index=ignore_index, verify_integrity=verify_integrity
2558-
)
2555+
return concat(
2556+
to_concat, ignore_index=ignore_index, verify_integrity=verify_integrity
25592557
)
25602558

25612559
def _binop(self, other, func, level=None, fill_value=None):

pandas/tests/series/methods/test_append.py

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

6262
tm.assert_series_equal(expected, result)
6363

64+
def test_append_dataframe_regression(self):
65+
# GH 30975
66+
df = pd.DataFrame({"A": [1, 2]})
67+
result = df.A.append([df])
68+
expected = pd.DataFrame(
69+
{0: [1.0, 2.0, None, None], "A": [None, None, 1.0, 2.0]}, index=[0, 1, 0, 1]
70+
)
71+
72+
tm.assert_frame_equal(expected, result)
73+
6474

6575
class TestSeriesAppendWithDatetimeIndex:
6676
def test_append(self):

0 commit comments

Comments
 (0)