Skip to content

Commit c82b88d

Browse files
author
Marco Gorelli
committed
🥅 raise more specific error if dict is appended to frame without ignore_index
1 parent b7fcb54 commit c82b88d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

pandas/core/frame.py

+2
Original file line numberDiff line numberDiff line change
@@ -7023,6 +7023,8 @@ def append(
70237023
"""
70247024
if isinstance(other, (Series, dict)):
70257025
if isinstance(other, dict):
7026+
if not ignore_index:
7027+
raise TypeError("Can only append a dict if ignore_index=True")
70267028
other = Series(other)
70277029
if other.name is None and not ignore_index:
70287030
raise TypeError(

pandas/tests/frame/methods/test_append.py

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def test_append_series_dict(self):
5050
)
5151
tm.assert_frame_equal(result, expected.loc[:, result.columns])
5252

53+
msg = "Can only append a dict if ignore_index=True"
54+
with pytest.raises(TypeError, match=msg):
55+
df.append(series.to_dict())
56+
5357
# can append when name set
5458
row = df.loc[4]
5559
row.name = 5

0 commit comments

Comments
 (0)