Skip to content

BUG: Fix Series.append raises TypeError with tuple of Series #28412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Other
- Trying to set the ``display.precision``, ``display.max_rows`` or ``display.max_columns`` using :meth:`set_option` to anything but a ``None`` or a positive int will raise a ``ValueError`` (:issue:`23348`)
- Using :meth:`DataFrame.replace` with overlapping keys in a nested dictionary will no longer raise, now matching the behavior of a flat dictionary (:issue:`27660`)
- :meth:`DataFrame.to_csv` and :meth:`Series.to_csv` now support dicts as ``compression`` argument with key ``'method'`` being the compression method and others as additional compression options when the compression method is ``'zip'``. (:issue:`26023`)
-
- :meth:`Series.append` will no longer raise a ``TypeError`` when passed a tuple of ``Series`` (:issue:`28410`)

.. _whatsnew_1000.contributors:

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2730,7 +2730,8 @@ def append(self, to_append, ignore_index=False, verify_integrity=False):
from pandas.core.reshape.concat import concat

if isinstance(to_append, (list, tuple)):
to_concat = [self] + to_append
to_concat = [self]
to_concat.extend(to_append)
else:
to_concat = [self, to_append]
return concat(
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/series/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ def test_append_duplicates(self):
with pytest.raises(ValueError, match=msg):
pd.concat([s1, s2], verify_integrity=True)

def test_append_tuples(self):
# GH 28410
s = pd.Series([1, 2, 3])
list_input = [s, s]
tuple_input = (s, s)

expected = s.append(list_input)
result = s.append(tuple_input)

tm.assert_series_equal(expected, result)

def test_combine_scalar(self):
# GH 21248
# Note - combine() with another Series is tested elsewhere because
Expand Down