From 7a3b6fe0d04f6fd972e76cc5045cfbb424187854 Mon Sep 17 00:00:00 2001 From: Harsha Date: Wed, 15 Jan 2020 03:13:53 -0600 Subject: [PATCH 01/19] GH 30975-Fix for Series.append(DataFrame) --- pandas/core/series.py | 3 +++ pandas/tests/series/methods/test_append.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index 33565bbedade6..aa4863586b5b2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2538,6 +2538,9 @@ def append(self, to_append, ignore_index=False, verify_integrity=False) -> "Seri to_concat = [self] to_concat.extend(to_append) else: + if not isinstance(to_append, type(self)): + msg = f"to_append should be a Series or list/tuple of Series, got {type(to_append)}" + raise TypeError(msg) to_concat = [self, to_append] return self._ensure_type( concat( diff --git a/pandas/tests/series/methods/test_append.py b/pandas/tests/series/methods/test_append.py index dc0fca4bba067..cc50598b4631f 100644 --- a/pandas/tests/series/methods/test_append.py +++ b/pandas/tests/series/methods/test_append.py @@ -61,6 +61,15 @@ def test_append_tuples(self): tm.assert_series_equal(expected, result) + def test_append_dataframe(self): + # GH 30975 + df = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) + df2 = pd.DataFrame({"C": [5, 6], "D": [7, 8]}) + + expected = pd.Series(pd.concat([df.A, df2.D])) + result = df.A.append(df2.D) + + tm.assert_series_equal(expected, result) class TestSeriesAppendWithDatetimeIndex: def test_append(self): From 8ea217fd6f00bfe8ef72d17001bdd9789ff5b74b Mon Sep 17 00:00:00 2001 From: Harsha Date: Wed, 15 Jan 2020 03:44:45 -0600 Subject: [PATCH 02/19] GH 30975-Fix for Series.append(DataFrame) --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index c423933d4c438..87c454bc5fceb 100755 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -1170,7 +1170,7 @@ Other - Bug where :meth:`DataFrame.itertuples` would incorrectly determine whether or not namedtuples could be used for dataframes of 255 columns (:issue:`28282`) - Handle nested NumPy ``object`` arrays in :func:`testing.assert_series_equal` for ExtensionArray implementations (:issue:`30841`) - Bug in :class:`Index` constructor incorrectly allowing 2-dimensional input arrays (:issue:`13601`, :issue:`27125`) - +- :meth:`Series.append` will now raise a ``TypeError`` when passed a DataFrame (:issue:`30975`) .. --------------------------------------------------------------------------- .. _whatsnew_100.contributors: From d5224386432ddc7cd93ebeebc9b39c252c2e4017 Mon Sep 17 00:00:00 2001 From: Harsha Date: Wed, 15 Jan 2020 04:02:40 -0600 Subject: [PATCH 03/19] GH 30975-Fix for Series.append(DataFrame) PEP-8 compliant --- pandas/core/series.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index aa4863586b5b2..faeb6bdbd8fba 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2539,7 +2539,8 @@ def append(self, to_append, ignore_index=False, verify_integrity=False) -> "Seri to_concat.extend(to_append) else: if not isinstance(to_append, type(self)): - msg = f"to_append should be a Series or list/tuple of Series, got {type(to_append)}" + msg = f"to_append should be a Series or list/tuple of Series, " \ + f"got {type(to_append)}" raise TypeError(msg) to_concat = [self, to_append] return self._ensure_type( From b717007ccbde5c0d873843811f22f14a4ae09e14 Mon Sep 17 00:00:00 2001 From: Harsha Date: Wed, 15 Jan 2020 04:27:00 -0600 Subject: [PATCH 04/19] GH 30975-Fix for Series.append(DataFrame) Adding TypeError Testcase --- pandas/tests/series/methods/test_append.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/tests/series/methods/test_append.py b/pandas/tests/series/methods/test_append.py index cc50598b4631f..e7dc184406036 100644 --- a/pandas/tests/series/methods/test_append.py +++ b/pandas/tests/series/methods/test_append.py @@ -71,6 +71,11 @@ def test_append_dataframe(self): tm.assert_series_equal(expected, result) + msg = "to_append should be a Series or list/tuple of Series, got " \ + "" + with pytest.raises(TypeError, match=msg): + df.A.append(df) + class TestSeriesAppendWithDatetimeIndex: def test_append(self): rng = date_range("5/8/2012 1:45", periods=10, freq="5T") From b584b356f1024cef02134662dc3a85a01776e467 Mon Sep 17 00:00:00 2001 From: Harsha Date: Wed, 15 Jan 2020 18:40:49 -0600 Subject: [PATCH 05/19] GH 30975-Fix for Series.append(DataFrame) Modified --- pandas/core/series.py | 14 ++++++++++---- pandas/tests/series/methods/test_append.py | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index faeb6bdbd8fba..4c7284a23232b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2534,15 +2534,21 @@ def append(self, to_append, ignore_index=False, verify_integrity=False) -> "Seri """ from pandas.core.reshape.concat import concat + is_sequence: bool = False if isinstance(to_append, (list, tuple)): to_concat = [self] to_concat.extend(to_append) + is_sequence = True else: - if not isinstance(to_append, type(self)): - msg = f"to_append should be a Series or list/tuple of Series, " \ - f"got {type(to_append)}" - raise TypeError(msg) to_concat = [self, to_append] + for x in to_concat[1:]: + if isinstance(x, (pd.DataFrame,)): + msg = ( + f"to_append should be a Series or list/tuple of Series, " + f"got {type(to_append).__name__} " + f'{("of "+type(x).__name__) if is_sequence else ""}' + ) + raise TypeError(msg) return self._ensure_type( concat( to_concat, ignore_index=ignore_index, verify_integrity=verify_integrity diff --git a/pandas/tests/series/methods/test_append.py b/pandas/tests/series/methods/test_append.py index e7dc184406036..1f59471785ec8 100644 --- a/pandas/tests/series/methods/test_append.py +++ b/pandas/tests/series/methods/test_append.py @@ -61,20 +61,21 @@ def test_append_tuples(self): tm.assert_series_equal(expected, result) - def test_append_dataframe(self): + def test_append_dataframe_raises(self): # GH 30975 df = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) - df2 = pd.DataFrame({"C": [5, 6], "D": [7, 8]}) + li = [df.B, df] - expected = pd.Series(pd.concat([df.A, df2.D])) - result = df.A.append(df2.D) - - tm.assert_series_equal(expected, result) - - msg = "to_append should be a Series or list/tuple of Series, got " \ - "" + msg = "to_append should be a Series or list/tuple of Series, got DataFrame" with pytest.raises(TypeError, match=msg): df.A.append(df) + msg = ( + "to_append should be a Series or list/tuple of Series," + " got list of DataFrame" + ) + with pytest.raises(TypeError, match=msg): + df.A.append(li) + class TestSeriesAppendWithDatetimeIndex: def test_append(self): From 1e5e8e7b1e2b16c8f7eeb58e982cc113fcd75923 Mon Sep 17 00:00:00 2001 From: Harsha Date: Wed, 15 Jan 2020 19:55:19 -0600 Subject: [PATCH 06/19] GH 30975-Fix for Series.append(DataFrame) Doc Build Fix --- doc/source/whatsnew/v1.0.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 87c454bc5fceb..67d5d9d8ae166 100755 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -1155,6 +1155,7 @@ Other - :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`) - Bug in :meth:`Series.diff` where a boolean series would incorrectly raise a ``TypeError`` (:issue:`17294`) - :meth:`Series.append` will no longer raise a ``TypeError`` when passed a tuple of ``Series`` (:issue:`28410`) +- :meth:`Series.append` will now raise a ``TypeError`` when passed a DataFrame (:issue:`30975`) - Fix corrupted error message when calling ``pandas.libs._json.encode()`` on a 0d array (:issue:`18878`) - Backtick quoting in :meth:`DataFrame.query` and :meth:`DataFrame.eval` can now also be used to use invalid identifiers like names that start with a digit, are python keywords, or are using single character operators. (:issue:`27017`) - Bug in ``pd.core.util.hashing.hash_pandas_object`` where arrays containing tuples were incorrectly treated as non-hashable (:issue:`28969`) @@ -1170,7 +1171,7 @@ Other - Bug where :meth:`DataFrame.itertuples` would incorrectly determine whether or not namedtuples could be used for dataframes of 255 columns (:issue:`28282`) - Handle nested NumPy ``object`` arrays in :func:`testing.assert_series_equal` for ExtensionArray implementations (:issue:`30841`) - Bug in :class:`Index` constructor incorrectly allowing 2-dimensional input arrays (:issue:`13601`, :issue:`27125`) -- :meth:`Series.append` will now raise a ``TypeError`` when passed a DataFrame (:issue:`30975`) + .. --------------------------------------------------------------------------- .. _whatsnew_100.contributors: From 53f1c112c7c11f043915a2f944f9d115d4c0a1af Mon Sep 17 00:00:00 2001 From: Harsha Date: Thu, 16 Jan 2020 20:53:01 -0600 Subject: [PATCH 07/19] GH 31087 Updates ggpy reference to plotnine --- doc/source/ecosystem.rst | 12 ++++++------ web/pandas/community/ecosystem.md | 11 +++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/doc/source/ecosystem.rst b/doc/source/ecosystem.rst index 7bd5ba7ecdf0b..5acbd83dc55cf 100644 --- a/doc/source/ecosystem.rst +++ b/doc/source/ecosystem.rst @@ -112,16 +112,16 @@ also goes beyond matplotlib and pandas with the option to perform statistical estimation while plotting, aggregating across observations and visualizing the fit of statistical models to emphasize patterns in a dataset. -`yhat/ggpy `__ -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`has2k1/plotnine `__ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hadley Wickham's `ggplot2 `__ is a foundational exploratory visualization package for the R language. Based on `"The Grammar of Graphics" `__ it provides a powerful, declarative and extremely general way to generate bespoke plots of any kind of data. -It's really quite incredible. Various implementations to other languages are available, -but a faithful implementation for Python users has long been missing. Although still young -(as of Jan-2014), the `yhat/ggpy `__ project has been -progressing quickly in that direction. +It's really quite incredible. Various implementations to other languages are available. +A good implementation for Python users is `has2k1/plotnine `__, +which started as an effort to improve the scaling functionality in +`yhat/ggpy `__ formally known as "ggplot for python." `IPython Vega `__ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/web/pandas/community/ecosystem.md b/web/pandas/community/ecosystem.md index af6fd1ac77605..677b329317c8e 100644 --- a/web/pandas/community/ecosystem.md +++ b/web/pandas/community/ecosystem.md @@ -84,7 +84,7 @@ pandas with the option to perform statistical estimation while plotting, aggregating across observations and visualizing the fit of statistical models to emphasize patterns in a dataset. -### [yhat/ggpy](https://github.com/yhat/ggpy) +### [has2k1/plotnine](https://github.com/has2k1/plotnine/) Hadley Wickham's [ggplot2](https://ggplot2.tidyverse.org/) is a foundational exploratory visualization package for the R language. Based @@ -92,11 +92,10 @@ on ["The Grammar of Graphics"](https://www.cs.uic.edu/~wilkinson/TheGrammarOfGraphics/GOG.html) it provides a powerful, declarative and extremely general way to generate bespoke plots of any kind of data. It's really quite -incredible. Various implementations to other languages are available, -but a faithful implementation for Python users has long been missing. -Although still young (as of Jan-2014), the -[yhat/ggpy](https://github.com/yhat/ggpy) project has been progressing -quickly in that direction. +incredible. Various implementations to other languages are available. +A good implementation for Python users is [has2k1/plotnine](https://github.com/has2k1/plotnine/), +which started as an effort to improve the scaling functionality in +[yhat/ggpy](https://github.com/yhat/ggpy) formally known as "ggplot for python.". ### [IPython Vega](https://github.com/vega/ipyvega) From 4e1f6b16d47b59c122b4561a4c92ccfb24d1284e Mon Sep 17 00:00:00 2001 From: Harsha Date: Thu, 16 Jan 2020 20:53:01 -0600 Subject: [PATCH 08/19] Revert "GH 31087 Updates ggpy reference to plotnine" This reverts commit 53f1c112c7c11f043915a2f944f9d115d4c0a1af. --- doc/source/ecosystem.rst | 12 ++++++------ web/pandas/community/ecosystem.md | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/doc/source/ecosystem.rst b/doc/source/ecosystem.rst index 5acbd83dc55cf..7bd5ba7ecdf0b 100644 --- a/doc/source/ecosystem.rst +++ b/doc/source/ecosystem.rst @@ -112,16 +112,16 @@ also goes beyond matplotlib and pandas with the option to perform statistical estimation while plotting, aggregating across observations and visualizing the fit of statistical models to emphasize patterns in a dataset. -`has2k1/plotnine `__ -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`yhat/ggpy `__ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hadley Wickham's `ggplot2 `__ is a foundational exploratory visualization package for the R language. Based on `"The Grammar of Graphics" `__ it provides a powerful, declarative and extremely general way to generate bespoke plots of any kind of data. -It's really quite incredible. Various implementations to other languages are available. -A good implementation for Python users is `has2k1/plotnine `__, -which started as an effort to improve the scaling functionality in -`yhat/ggpy `__ formally known as "ggplot for python." +It's really quite incredible. Various implementations to other languages are available, +but a faithful implementation for Python users has long been missing. Although still young +(as of Jan-2014), the `yhat/ggpy `__ project has been +progressing quickly in that direction. `IPython Vega `__ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/web/pandas/community/ecosystem.md b/web/pandas/community/ecosystem.md index 677b329317c8e..af6fd1ac77605 100644 --- a/web/pandas/community/ecosystem.md +++ b/web/pandas/community/ecosystem.md @@ -84,7 +84,7 @@ pandas with the option to perform statistical estimation while plotting, aggregating across observations and visualizing the fit of statistical models to emphasize patterns in a dataset. -### [has2k1/plotnine](https://github.com/has2k1/plotnine/) +### [yhat/ggpy](https://github.com/yhat/ggpy) Hadley Wickham's [ggplot2](https://ggplot2.tidyverse.org/) is a foundational exploratory visualization package for the R language. Based @@ -92,10 +92,11 @@ on ["The Grammar of Graphics"](https://www.cs.uic.edu/~wilkinson/TheGrammarOfGraphics/GOG.html) it provides a powerful, declarative and extremely general way to generate bespoke plots of any kind of data. It's really quite -incredible. Various implementations to other languages are available. -A good implementation for Python users is [has2k1/plotnine](https://github.com/has2k1/plotnine/), -which started as an effort to improve the scaling functionality in -[yhat/ggpy](https://github.com/yhat/ggpy) formally known as "ggplot for python.". +incredible. Various implementations to other languages are available, +but a faithful implementation for Python users has long been missing. +Although still young (as of Jan-2014), the +[yhat/ggpy](https://github.com/yhat/ggpy) project has been progressing +quickly in that direction. ### [IPython Vega](https://github.com/vega/ipyvega) From 041ed129499808bbf694753b352141d06448e6b7 Mon Sep 17 00:00:00 2001 From: Harsha Date: Thu, 16 Jan 2020 20:53:01 -0600 Subject: [PATCH 09/19] Revert "GH 31087 Updates ggpy reference to plotnine" This reverts commit 53f1c112c7c11f043915a2f944f9d115d4c0a1af. From 721a56074c8e1f7ad78e994b232437f657cff4da Mon Sep 17 00:00:00 2001 From: Harsha Date: Fri, 17 Jan 2020 14:04:58 -0600 Subject: [PATCH 10/19] GH 30975-Fix for Series.append(DataFrame) Simple message change --- pandas/core/series.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 4c7284a23232b..8f0b23b934fe0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2534,19 +2534,16 @@ def append(self, to_append, ignore_index=False, verify_integrity=False) -> "Seri """ from pandas.core.reshape.concat import concat - is_sequence: bool = False if isinstance(to_append, (list, tuple)): to_concat = [self] to_concat.extend(to_append) - is_sequence = True else: to_concat = [self, to_append] for x in to_concat[1:]: if isinstance(x, (pd.DataFrame,)): msg = ( f"to_append should be a Series or list/tuple of Series, " - f"got {type(to_append).__name__} " - f'{("of "+type(x).__name__) if is_sequence else ""}' + f"got {type(to_append).__name__}" ) raise TypeError(msg) return self._ensure_type( From f312bae4e6669e29f67e1ac730a4ac0f565abc51 Mon Sep 17 00:00:00 2001 From: Harsha Date: Fri, 17 Jan 2020 14:47:42 -0600 Subject: [PATCH 11/19] GH 30975-Fix for Series.append(DataFrame) Simple message test change --- pandas/tests/series/methods/test_append.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/tests/series/methods/test_append.py b/pandas/tests/series/methods/test_append.py index 1f59471785ec8..f604d6bd02935 100644 --- a/pandas/tests/series/methods/test_append.py +++ b/pandas/tests/series/methods/test_append.py @@ -69,10 +69,7 @@ def test_append_dataframe_raises(self): msg = "to_append should be a Series or list/tuple of Series, got DataFrame" with pytest.raises(TypeError, match=msg): df.A.append(df) - msg = ( - "to_append should be a Series or list/tuple of Series," - " got list of DataFrame" - ) + msg = "to_append should be a Series or list/tuple of Series, got list" with pytest.raises(TypeError, match=msg): df.A.append(li) From a1ebee2207e11456e14f68db940030969c0749f9 Mon Sep 17 00:00:00 2001 From: Harsha Date: Sat, 18 Jan 2020 20:26:56 -0600 Subject: [PATCH 12/19] GH 30975-Fix for Series.append(DataFrame) Removed self._ensure_type --- pandas/core/series.py | 10 ++++------ pandas/tests/series/methods/test_append.py | 4 +--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 8f0b23b934fe0..c4dd23e40a327 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2540,16 +2540,14 @@ def append(self, to_append, ignore_index=False, verify_integrity=False) -> "Seri else: to_concat = [self, to_append] for x in to_concat[1:]: - if isinstance(x, (pd.DataFrame,)): + if isinstance(x, ABCDataFrame): msg = ( f"to_append should be a Series or list/tuple of Series, " - f"got {type(to_append).__name__}" + f"got {type(x).__name__}" ) raise TypeError(msg) - return self._ensure_type( - concat( - to_concat, ignore_index=ignore_index, verify_integrity=verify_integrity - ) + return concat( + to_concat, ignore_index=ignore_index, verify_integrity=verify_integrity ) def _binop(self, other, func, level=None, fill_value=None): diff --git a/pandas/tests/series/methods/test_append.py b/pandas/tests/series/methods/test_append.py index f604d6bd02935..f65072abd9d25 100644 --- a/pandas/tests/series/methods/test_append.py +++ b/pandas/tests/series/methods/test_append.py @@ -64,14 +64,12 @@ def test_append_tuples(self): def test_append_dataframe_raises(self): # GH 30975 df = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) - li = [df.B, df] msg = "to_append should be a Series or list/tuple of Series, got DataFrame" with pytest.raises(TypeError, match=msg): df.A.append(df) - msg = "to_append should be a Series or list/tuple of Series, got list" with pytest.raises(TypeError, match=msg): - df.A.append(li) + df.A.append([df]) class TestSeriesAppendWithDatetimeIndex: From 32d29892ec57234d613770f677f1044c4fb0e910 Mon Sep 17 00:00:00 2001 From: Harsha Date: Sat, 18 Jan 2020 21:10:22 -0600 Subject: [PATCH 13/19] GH 30975-Fix for Series.append(DataFrame) Removed self._ensure_type return type change --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index c4dd23e40a327..862f97dad9b8b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2462,7 +2462,7 @@ def searchsorted(self, value, side="left", sorter=None): # ------------------------------------------------------------------- # Combination - def append(self, to_append, ignore_index=False, verify_integrity=False) -> "Series": + def append(self, to_append, ignore_index=False, verify_integrity=False): """ Concatenate two or more Series. From 87ea2aa532efd6cf2ec3c3c5603e957943ef98e8 Mon Sep 17 00:00:00 2001 From: Harsha Date: Mon, 20 Jan 2020 04:13:30 -0600 Subject: [PATCH 14/19] GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour --- doc/source/whatsnew/v1.0.0.rst | 1 - pandas/core/series.py | 13 ++++--------- pandas/tests/series/methods/test_append.py | 14 +++++++------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 67d5d9d8ae166..c423933d4c438 100755 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -1155,7 +1155,6 @@ Other - :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`) - Bug in :meth:`Series.diff` where a boolean series would incorrectly raise a ``TypeError`` (:issue:`17294`) - :meth:`Series.append` will no longer raise a ``TypeError`` when passed a tuple of ``Series`` (:issue:`28410`) -- :meth:`Series.append` will now raise a ``TypeError`` when passed a DataFrame (:issue:`30975`) - Fix corrupted error message when calling ``pandas.libs._json.encode()`` on a 0d array (:issue:`18878`) - Backtick quoting in :meth:`DataFrame.query` and :meth:`DataFrame.eval` can now also be used to use invalid identifiers like names that start with a digit, are python keywords, or are using single character operators. (:issue:`27017`) - Bug in ``pd.core.util.hashing.hash_pandas_object`` where arrays containing tuples were incorrectly treated as non-hashable (:issue:`28969`) diff --git a/pandas/core/series.py b/pandas/core/series.py index 862f97dad9b8b..177301ba931cc 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -23,7 +23,7 @@ from pandas._config import get_option from pandas._libs import index as libindex, lib, reshape, tslibs -from pandas._typing import Label +from pandas._typing import Label, FrameOrSeriesUnion from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution from pandas.util._validators import validate_bool_kwarg, validate_percentile @@ -2462,7 +2462,9 @@ def searchsorted(self, value, side="left", sorter=None): # ------------------------------------------------------------------- # Combination - def append(self, to_append, ignore_index=False, verify_integrity=False): + def append( + self, to_append, ignore_index=False, verify_integrity=False + ) -> FrameOrSeriesUnion: """ Concatenate two or more Series. @@ -2539,13 +2541,6 @@ def append(self, to_append, ignore_index=False, verify_integrity=False): to_concat.extend(to_append) else: to_concat = [self, to_append] - for x in to_concat[1:]: - if isinstance(x, ABCDataFrame): - msg = ( - f"to_append should be a Series or list/tuple of Series, " - f"got {type(x).__name__}" - ) - raise TypeError(msg) return concat( to_concat, ignore_index=ignore_index, verify_integrity=verify_integrity ) diff --git a/pandas/tests/series/methods/test_append.py b/pandas/tests/series/methods/test_append.py index f65072abd9d25..4d64b5b397981 100644 --- a/pandas/tests/series/methods/test_append.py +++ b/pandas/tests/series/methods/test_append.py @@ -61,15 +61,15 @@ def test_append_tuples(self): tm.assert_series_equal(expected, result) - def test_append_dataframe_raises(self): + def test_append_dataframe_regression(self): # GH 30975 - df = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) + df = pd.DataFrame({"A": [1, 2]}) + result = df.A.append([df]) + expected = pd.DataFrame( + {0: [1.0, 2.0, None, None], "A": [None, None, 1.0, 2.0]}, index=[0, 1, 0, 1] + ) - msg = "to_append should be a Series or list/tuple of Series, got DataFrame" - with pytest.raises(TypeError, match=msg): - df.A.append(df) - with pytest.raises(TypeError, match=msg): - df.A.append([df]) + tm.assert_frame_equal(expected, result) class TestSeriesAppendWithDatetimeIndex: From 19dcea3e344e5676ff714e68673d1fb0f616b785 Mon Sep 17 00:00:00 2001 From: Harsha Date: Mon, 20 Jan 2020 14:23:41 -0600 Subject: [PATCH 15/19] GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour return typing fix --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 177301ba931cc..9521808aeb499 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -23,7 +23,7 @@ from pandas._config import get_option from pandas._libs import index as libindex, lib, reshape, tslibs -from pandas._typing import Label, FrameOrSeriesUnion +from pandas._typing import FrameOrSeries, Label from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution from pandas.util._validators import validate_bool_kwarg, validate_percentile @@ -2464,7 +2464,7 @@ def searchsorted(self, value, side="left", sorter=None): def append( self, to_append, ignore_index=False, verify_integrity=False - ) -> FrameOrSeriesUnion: + ) -> FrameOrSeries: """ Concatenate two or more Series. From cdf92ae4cdeb59a1bcff107c2c0a2de343ca2488 Mon Sep 17 00:00:00 2001 From: Harsha Date: Mon, 20 Jan 2020 15:16:38 -0600 Subject: [PATCH 16/19] GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour return typing fix --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 9521808aeb499..b415dcc29a952 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -23,7 +23,7 @@ from pandas._config import get_option from pandas._libs import index as libindex, lib, reshape, tslibs -from pandas._typing import FrameOrSeries, Label +from pandas._typing import FrameOrSeriesUnion, Label from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution from pandas.util._validators import validate_bool_kwarg, validate_percentile @@ -2464,7 +2464,7 @@ def searchsorted(self, value, side="left", sorter=None): def append( self, to_append, ignore_index=False, verify_integrity=False - ) -> FrameOrSeries: + ) -> FrameOrSeriesUnion: """ Concatenate two or more Series. From a74792146db2c4340ee7ca20b7ee66a71cf614fa Mon Sep 17 00:00:00 2001 From: Harsha Date: Mon, 20 Jan 2020 16:14:01 -0600 Subject: [PATCH 17/19] GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour return typing fix --- pandas/core/series.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index b415dcc29a952..2076d83248861 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -23,7 +23,7 @@ from pandas._config import get_option from pandas._libs import index as libindex, lib, reshape, tslibs -from pandas._typing import FrameOrSeriesUnion, Label +from pandas._typing import Label from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution from pandas.util._validators import validate_bool_kwarg, validate_percentile @@ -2462,9 +2462,7 @@ def searchsorted(self, value, side="left", sorter=None): # ------------------------------------------------------------------- # Combination - def append( - self, to_append, ignore_index=False, verify_integrity=False - ) -> FrameOrSeriesUnion: + def append(self, to_append, ignore_index=False, verify_integrity=False): """ Concatenate two or more Series. From a256fe8573cc16bee1586c558bb0c152eb8728df Mon Sep 17 00:00:00 2001 From: Harsha Date: Mon, 20 Jan 2020 23:53:46 -0600 Subject: [PATCH 18/19] GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour return typing fix --- pandas/core/series.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 2076d83248861..b415dcc29a952 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -23,7 +23,7 @@ from pandas._config import get_option from pandas._libs import index as libindex, lib, reshape, tslibs -from pandas._typing import Label +from pandas._typing import FrameOrSeriesUnion, Label from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution from pandas.util._validators import validate_bool_kwarg, validate_percentile @@ -2462,7 +2462,9 @@ def searchsorted(self, value, side="left", sorter=None): # ------------------------------------------------------------------- # Combination - def append(self, to_append, ignore_index=False, verify_integrity=False): + def append( + self, to_append, ignore_index=False, verify_integrity=False + ) -> FrameOrSeriesUnion: """ Concatenate two or more Series. From 14e0fb49bee7008ee9c5b98aaadded4bf89daf25 Mon Sep 17 00:00:00 2001 From: Harsha Date: Tue, 21 Jan 2020 00:02:30 -0600 Subject: [PATCH 19/19] GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour return typing fix --- pandas/core/series.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index b415dcc29a952..2076d83248861 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -23,7 +23,7 @@ from pandas._config import get_option from pandas._libs import index as libindex, lib, reshape, tslibs -from pandas._typing import FrameOrSeriesUnion, Label +from pandas._typing import Label from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution from pandas.util._validators import validate_bool_kwarg, validate_percentile @@ -2462,9 +2462,7 @@ def searchsorted(self, value, side="left", sorter=None): # ------------------------------------------------------------------- # Combination - def append( - self, to_append, ignore_index=False, verify_integrity=False - ) -> FrameOrSeriesUnion: + def append(self, to_append, ignore_index=False, verify_integrity=False): """ Concatenate two or more Series.