From 3c390fe7ca1a321d4e5b99551e24f4dec405eac7 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 22 Mar 2023 14:19:21 +0000 Subject: [PATCH 01/14] DEPR: Deprecate returning a DataFrame in SeriesApply.apply_standard --- doc/source/whatsnew/v2.1.0.rst | 2 ++ pandas/core/apply.py | 9 +++++++++ pandas/tests/apply/test_series_apply.py | 15 +++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 69a955dc3cd9f..8902fa24b7f02 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -127,6 +127,8 @@ Deprecations - Deprecated logical operations (``|``, ``&``, ``^``) between pandas objects and dtype-less sequences (e.g. ``list``, ``tuple``), wrap a sequence in a :class:`Series` or numpy array before operating instead (:issue:`51521`) - Deprecated :meth:`DataFrame.swapaxes` and :meth:`Series.swapaxes`, use :meth:`DataFrame.transpose` or :meth:`Series.transpose` instead (:issue:`51946`) - Deprecated parameter ``convert_type`` in :meth:`Series.apply` (:issue:`52140`) +- Deprecated making :meth:`Series.apply` return a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object. In the future this will return a :class:`Series`. + This pattern was very slow and it's recommended to use alternative methods to archive the same goal (:issue:`52116`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 2ffd49f674cfb..855b1ac80b9f4 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -19,6 +19,7 @@ Sequence, cast, ) +import warnings import numpy as np @@ -36,6 +37,7 @@ ) from pandas.errors import SpecificationError from pandas.util._decorators import cache_readonly +from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.cast import is_nested_object from pandas.core.dtypes.common import ( @@ -1091,6 +1093,13 @@ def apply_standard(self) -> DataFrame | Series: mapped = obj._map_values(mapper=f, na_action=action, convert=self.convert_dtype) if len(mapped) and isinstance(mapped[0], ABCSeries): + warnings.warn( + "converting list of Series to a DataFrame in the Series.apply method " + "is deprecated and will be removed in the future version.", + FutureWarning, + stacklevel=find_stack_level(), + ) # GH52116 + # GH#43986 Need to do list(mapped) in order to get treated as nested # See also GH#25959 regarding EA support return obj._constructor_expanddim(list(mapped), index=obj.index) diff --git a/pandas/tests/apply/test_series_apply.py b/pandas/tests/apply/test_series_apply.py index 043f1275a9395..21c1316fa7673 100644 --- a/pandas/tests/apply/test_series_apply.py +++ b/pandas/tests/apply/test_series_apply.py @@ -381,11 +381,15 @@ def test_agg_apply_evaluate_lambdas_the_same(string_series): def test_with_nested_series(datetime_series): # GH 2316 # .agg with a reducer and a transform, what to do - result = datetime_series.apply(lambda x: Series([x, x**2], index=["x", "x^2"])) + with tm.assert_produces_warning(FutureWarning): + result = datetime_series.apply( + lambda x: Series([x, x**2], index=["x", "x^2"]) + ) expected = DataFrame({"x": datetime_series, "x^2": datetime_series**2}) tm.assert_frame_equal(result, expected) - result = datetime_series.agg(lambda x: Series([x, x**2], index=["x", "x^2"])) + with tm.assert_produces_warning(FutureWarning): + result = datetime_series.agg(lambda x: Series([x, x**2], index=["x", "x^2"])) tm.assert_frame_equal(result, expected) @@ -857,7 +861,8 @@ def test_apply_series_on_date_time_index_aware_series(dti, exp, aware): index = dti.tz_localize("UTC").index else: index = dti.index - result = Series(index).apply(lambda x: Series([1, 2])) + with tm.assert_produces_warning(FutureWarning): + result = Series(index).apply(lambda x: Series([1, 2])) tm.assert_frame_equal(result, exp) @@ -966,7 +971,9 @@ def test_apply_dictlike_transformer(string_series, ops): def test_apply_retains_column_name(): # GH 16380 df = DataFrame({"x": range(3)}, Index(range(3), name="x")) - result = df.x.apply(lambda x: Series(range(x + 1), Index(range(x + 1), name="y"))) + func = lambda x: Series(range(x + 1), Index(range(x + 1), name="y")) + with tm.assert_produces_warning(FutureWarning): + result = df.x.apply(func) expected = DataFrame( [[0.0, np.nan, np.nan], [0.0, 1.0, np.nan], [0.0, 1.0, 2.0]], columns=Index(range(3), name="y"), From 4c0274a6dd917f4c57e475f5bc258b982f719b10 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 22 Mar 2023 19:09:59 +0000 Subject: [PATCH 02/14] fix warning --- pandas/core/apply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 855b1ac80b9f4..bc961c86b05fd 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -1095,7 +1095,7 @@ def apply_standard(self) -> DataFrame | Series: if len(mapped) and isinstance(mapped[0], ABCSeries): warnings.warn( "converting list of Series to a DataFrame in the Series.apply method " - "is deprecated and will be removed in the future version.", + "is deprecated and will be removed in a future version.", FutureWarning, stacklevel=find_stack_level(), ) # GH52116 From 3ffe69cc7c7c28992d087c969ecb1508c07eaab9 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 22 Mar 2023 19:15:01 +0000 Subject: [PATCH 03/14] fix tests --- pandas/tests/apply/test_series_apply.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pandas/tests/apply/test_series_apply.py b/pandas/tests/apply/test_series_apply.py index 21c1316fa7673..4f8e27e909dee 100644 --- a/pandas/tests/apply/test_series_apply.py +++ b/pandas/tests/apply/test_series_apply.py @@ -381,14 +381,16 @@ def test_agg_apply_evaluate_lambdas_the_same(string_series): def test_with_nested_series(datetime_series): # GH 2316 # .agg with a reducer and a transform, what to do - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, match="converting list of Series"): + # GH52123 result = datetime_series.apply( lambda x: Series([x, x**2], index=["x", "x^2"]) ) expected = DataFrame({"x": datetime_series, "x^2": datetime_series**2}) tm.assert_frame_equal(result, expected) - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, match="converting list of Series"): + # GH52123 result = datetime_series.agg(lambda x: Series([x, x**2], index=["x", "x^2"])) tm.assert_frame_equal(result, expected) @@ -861,7 +863,8 @@ def test_apply_series_on_date_time_index_aware_series(dti, exp, aware): index = dti.tz_localize("UTC").index else: index = dti.index - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, match="converting list of Series"): + # GH52123 result = Series(index).apply(lambda x: Series([1, 2])) tm.assert_frame_equal(result, exp) @@ -972,7 +975,8 @@ def test_apply_retains_column_name(): # GH 16380 df = DataFrame({"x": range(3)}, Index(range(3), name="x")) func = lambda x: Series(range(x + 1), Index(range(x + 1), name="y")) - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, match="converting list of Series"): + # GH52123 result = df.x.apply(func) expected = DataFrame( [[0.0, np.nan, np.nan], [0.0, 1.0, np.nan], [0.0, 1.0, 2.0]], From 4847f783c588e8befcb4c9d0fa7df1a3c6e7f153 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 22 Mar 2023 21:24:36 +0000 Subject: [PATCH 04/14] fix cookbook.rst example --- doc/source/user_guide/cookbook.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/source/user_guide/cookbook.rst b/doc/source/user_guide/cookbook.rst index daf5a0e481b8e..3a0aad41933bc 100644 --- a/doc/source/user_guide/cookbook.rst +++ b/doc/source/user_guide/cookbook.rst @@ -794,12 +794,12 @@ Apply index=["I", "II", "III"], ) - def SeriesFromSubList(aList): - return pd.Series(aList) + def make_df(ser): + new_vals = [pd.Series(value, name=name) for name, value in ser.items()] + return pd.DataFrame(new_vals) + + df_orgz = pd.concat({ind: row.pipe(make_df) for ind, row in df.iterrows()}) - df_orgz = pd.concat( - {ind: row.apply(SeriesFromSubList) for ind, row in df.iterrows()} - ) df_orgz `Rolling apply with a DataFrame returning a Series From ffc0928657a42d38a1e34a256711a7d576aaca9b Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 23 Mar 2023 06:55:34 +0000 Subject: [PATCH 05/14] fix code examples --- doc/source/user_guide/groupby.rst | 17 ----------------- doc/source/whatsnew/v0.10.0.rst | 28 ++++++++++++++++++++-------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index ed1689f0c9f79..0c778261ff699 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -1221,23 +1221,6 @@ The dimension of the returned result can also change: grouped.apply(f) -``apply`` on a Series can operate on a returned value from the applied function -that is itself a series, and possibly upcast the result to a DataFrame: - -.. ipython:: python - - def f(x): - return pd.Series([x, x ** 2], index=["x", "x^2"]) - - - s = pd.Series(np.random.rand(5)) - s - s.apply(f) - -Similar to :ref:`groupby.aggregate.agg`, the resulting dtype will reflect that of the -apply function. If the results from different groups have different dtypes, then -a common dtype will be determined in the same way as ``DataFrame`` construction. - Control grouped column(s) placement with ``group_keys`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/source/whatsnew/v0.10.0.rst b/doc/source/whatsnew/v0.10.0.rst index bd47e6e4bc025..cacca08414896 100644 --- a/doc/source/whatsnew/v0.10.0.rst +++ b/doc/source/whatsnew/v0.10.0.rst @@ -243,15 +243,27 @@ Convenience methods ``ffill`` and ``bfill`` have been added: function, that is itself a series, and possibly upcast the result to a DataFrame - .. ipython:: python - - def f(x): - return pd.Series([x, x ** 2], index=["x", "x^2"]) - + .. code-block:: python + + >>> def f(x): + ... return pd.Series([x, x ** 2], index=["x", "x^2"]) + >>> + >>> s = pd.Series(np.random.rand(5)) + >>> s + 0 0.340445 + 1 0.984729 + 2 0.919540 + 3 0.037772 + 4 0.861549 + dtype: float64 + >>> s.apply(f) + x x^2 + 0 0.340445 0.115903 + 1 0.984729 0.969691 + 2 0.919540 0.845555 + 3 0.037772 0.001427 + 4 0.861549 0.742267 - s = pd.Series(np.random.rand(5)) - s - s.apply(f) - New API functions for working with pandas options (:issue:`2097`): From ca3478af90cc40743f66d93da887edacaa7d55a0 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 23 Mar 2023 07:00:09 +0000 Subject: [PATCH 06/14] fix code examples II --- doc/source/user_guide/groupby.rst | 18 ++++++++++++++++++ doc/source/whatsnew/v0.10.0.rst | 29 +++++++++-------------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 0c778261ff699..289605efbbc97 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -1221,6 +1221,24 @@ The dimension of the returned result can also change: grouped.apply(f) +``apply`` on a Series can operate on a returned value from the applied function +that is itself a series, and possibly upcast the result to a DataFrame: + +.. ipython:: python + :okwarning: + + def f(x): + return pd.Series([x, x ** 2], index=["x", "x^2"]) + + + s = pd.Series(np.random.rand(5)) + s + s.apply(f) + +Similar to :ref:`groupby.aggregate.agg`, the resulting dtype will reflect that of the +apply function. If the results from different groups have different dtypes, then +a common dtype will be determined in the same way as ``DataFrame`` construction. + Control grouped column(s) placement with ``group_keys`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/source/whatsnew/v0.10.0.rst b/doc/source/whatsnew/v0.10.0.rst index cacca08414896..5beb569e00827 100644 --- a/doc/source/whatsnew/v0.10.0.rst +++ b/doc/source/whatsnew/v0.10.0.rst @@ -243,27 +243,16 @@ Convenience methods ``ffill`` and ``bfill`` have been added: function, that is itself a series, and possibly upcast the result to a DataFrame - .. code-block:: python - - >>> def f(x): - ... return pd.Series([x, x ** 2], index=["x", "x^2"]) - >>> - >>> s = pd.Series(np.random.rand(5)) - >>> s - 0 0.340445 - 1 0.984729 - 2 0.919540 - 3 0.037772 - 4 0.861549 - dtype: float64 - >>> s.apply(f) - x x^2 - 0 0.340445 0.115903 - 1 0.984729 0.969691 - 2 0.919540 0.845555 - 3 0.037772 0.001427 - 4 0.861549 0.742267 + .. ipython:: python + :okwarning: + + def f(x): + return pd.Series([x, x ** 2], index=["x", "x^2"]) + + s = pd.Series(np.random.rand(5)) + s + s.apply(f) - New API functions for working with pandas options (:issue:`2097`): From e66c23f4e2f513fe2f9d6877dee36b33bb00c3f4 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 23 Mar 2023 08:35:29 +0000 Subject: [PATCH 07/14] fix code examples III --- doc/source/user_guide/groupby.rst | 2 +- doc/source/whatsnew/v0.10.0.rst | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 289605efbbc97..53151cb71e44a 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -1225,7 +1225,7 @@ The dimension of the returned result can also change: that is itself a series, and possibly upcast the result to a DataFrame: .. ipython:: python - :okwarning: + :okwarning: def f(x): return pd.Series([x, x ** 2], index=["x", "x^2"]) diff --git a/doc/source/whatsnew/v0.10.0.rst b/doc/source/whatsnew/v0.10.0.rst index 5beb569e00827..388e716d122a5 100644 --- a/doc/source/whatsnew/v0.10.0.rst +++ b/doc/source/whatsnew/v0.10.0.rst @@ -243,16 +243,26 @@ Convenience methods ``ffill`` and ``bfill`` have been added: function, that is itself a series, and possibly upcast the result to a DataFrame - .. ipython:: python - :okwarning: - - def f(x): - return pd.Series([x, x ** 2], index=["x", "x^2"]) - - - s = pd.Series(np.random.rand(5)) - s - s.apply(f) + .. code-block:: python + + >>> def f(x): + ... return pd.Series([x, x ** 2], index=["x", "x^2"]) + >>> + >>> s = pd.Series(np.random.rand(5)) + >>> s + 0 0.340445 + 1 0.984729 + 2 0.919540 + 3 0.037772 + 4 0.861549 + dtype: float64 + >>> s.apply(f) + x x^2 + 0 0.340445 0.115903 + 1 0.984729 0.969691 + 2 0.919540 0.845555 + 3 0.037772 0.001427 + 4 0.861549 0.742267 - New API functions for working with pandas options (:issue:`2097`): From 21811d016f3d78ee0daba9bcfb2d4817ddfdc50c Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 23 Mar 2023 12:20:49 +0000 Subject: [PATCH 08/14] add deprecation message to Series.apply --- pandas/core/series.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index c1997331ed06d..eaa1916318069 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4415,6 +4415,12 @@ def apply( Can be ufunc (a NumPy function that applies to the entire Series) or a Python function that only works on single values. + .. deprecated:: 2.1.0 + + If the output from ``func`` is a listlike of ``Series`` the output, + wrapping the output in a ``DataFrame`` instead of a ``Series`` has been + deprecated. + Parameters ---------- func : function From 06d498bdedb372b0412f8abd2b1263dc05d220b7 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 23 Mar 2023 14:34:35 +0000 Subject: [PATCH 09/14] add deprecation message to Series.apply II --- pandas/core/series.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index eaa1916318069..a4bebdd260480 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4412,14 +4412,13 @@ def apply( """ Invoke function on values of Series. - Can be ufunc (a NumPy function that applies to the entire Series) - or a Python function that only works on single values. - .. deprecated:: 2.1.0 - If the output from ``func`` is a listlike of ``Series`` the output, - wrapping the output in a ``DataFrame`` instead of a ``Series`` has been - deprecated. + If the result from ``func`` is a ``Series``, wrapping the output in a + ``DataFrame`` instead of a ``Series`` has been deprecated. + + Can be ufunc (a NumPy function that applies to the entire Series) + or a Python function that only works on single values. Parameters ---------- From 6a0f6c2ab1f3ef5d0e6b9ac97af107c4d8e4b3be Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Fri, 24 Mar 2023 18:15:07 +0000 Subject: [PATCH 10/14] clearer error message --- pandas/core/apply.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index bc961c86b05fd..53c63132b2602 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -1094,8 +1094,9 @@ def apply_standard(self) -> DataFrame | Series: if len(mapped) and isinstance(mapped[0], ABCSeries): warnings.warn( - "converting list of Series to a DataFrame in the Series.apply method " - "is deprecated and will be removed in a future version.", + "Returning a DataFrame from Series.apply when the supplied function" + "returns a Series is deprecated and will be removed in a future " + "version.", FutureWarning, stacklevel=find_stack_level(), ) # GH52116 From fe857a4c78b20de9f6ebbfa63e31fe0ca29d3cac Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Fri, 24 Mar 2023 19:56:47 +0000 Subject: [PATCH 11/14] fix tests --- pandas/tests/apply/test_series_apply.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pandas/tests/apply/test_series_apply.py b/pandas/tests/apply/test_series_apply.py index 4f8e27e909dee..932e6947321a1 100644 --- a/pandas/tests/apply/test_series_apply.py +++ b/pandas/tests/apply/test_series_apply.py @@ -381,7 +381,8 @@ def test_agg_apply_evaluate_lambdas_the_same(string_series): def test_with_nested_series(datetime_series): # GH 2316 # .agg with a reducer and a transform, what to do - with tm.assert_produces_warning(FutureWarning, match="converting list of Series"): + msg = "Returning a DataFrame from Series.apply when the supplied function" + with tm.assert_produces_warning(FutureWarning, match=msg): # GH52123 result = datetime_series.apply( lambda x: Series([x, x**2], index=["x", "x^2"]) @@ -389,7 +390,7 @@ def test_with_nested_series(datetime_series): expected = DataFrame({"x": datetime_series, "x^2": datetime_series**2}) tm.assert_frame_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, match="converting list of Series"): + with tm.assert_produces_warning(FutureWarning, match=msg): # GH52123 result = datetime_series.agg(lambda x: Series([x, x**2], index=["x", "x^2"])) tm.assert_frame_equal(result, expected) @@ -863,7 +864,8 @@ def test_apply_series_on_date_time_index_aware_series(dti, exp, aware): index = dti.tz_localize("UTC").index else: index = dti.index - with tm.assert_produces_warning(FutureWarning, match="converting list of Series"): + msg = "Returning a DataFrame from Series.apply when the supplied function" + with tm.assert_produces_warning(FutureWarning, match=msg): # GH52123 result = Series(index).apply(lambda x: Series([1, 2])) tm.assert_frame_equal(result, exp) @@ -975,7 +977,8 @@ def test_apply_retains_column_name(): # GH 16380 df = DataFrame({"x": range(3)}, Index(range(3), name="x")) func = lambda x: Series(range(x + 1), Index(range(x + 1), name="y")) - with tm.assert_produces_warning(FutureWarning, match="converting list of Series"): + msg = "Returning a DataFrame from Series.apply when the supplied function" + with tm.assert_produces_warning(FutureWarning, match=msg): # GH52123 result = df.x.apply(func) expected = DataFrame( From 41d12746a4ac8a85feb0a22f6eb5b56843bbaced Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 5 Apr 2023 23:18:27 +0100 Subject: [PATCH 12/14] adjust whatsnew for comments --- doc/source/whatsnew/v2.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 94c9aefe343db..39f210464be3a 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -172,7 +172,7 @@ Deprecations - Deprecated the methods :meth:`Series.bool` and :meth:`DataFrame.bool` (:issue:`51749`) - Deprecated :meth:`DataFrame.swapaxes` and :meth:`Series.swapaxes`, use :meth:`DataFrame.transpose` or :meth:`Series.transpose` instead (:issue:`51946`) - Deprecated parameter ``convert_type`` in :meth:`Series.apply` (:issue:`52140`) -- Deprecated making :meth:`Series.apply` return a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object. In the future this will return a :class:`Series`. +- Deprecated making :meth:`Series.apply` return a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object. In the future this will return a :class:`Series` whose values are themselves :class:`Series`. This pattern was very slow and it's recommended to use alternative methods to archive the same goal (:issue:`52116`) - From d5ba26043b97d5b9cddc0e36364646a9da0d707b Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 6 Apr 2023 07:43:45 +0100 Subject: [PATCH 13/14] doc issues --- doc/source/user_guide/groupby.rst | 14 -------------- doc/source/whatsnew/v2.1.0.rst | 3 +-- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 53151cb71e44a..d301373bb6eea 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -1221,20 +1221,6 @@ The dimension of the returned result can also change: grouped.apply(f) -``apply`` on a Series can operate on a returned value from the applied function -that is itself a series, and possibly upcast the result to a DataFrame: - -.. ipython:: python - :okwarning: - - def f(x): - return pd.Series([x, x ** 2], index=["x", "x^2"]) - - - s = pd.Series(np.random.rand(5)) - s - s.apply(f) - Similar to :ref:`groupby.aggregate.agg`, the resulting dtype will reflect that of the apply function. If the results from different groups have different dtypes, then a common dtype will be determined in the same way as ``DataFrame`` construction. diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 39f210464be3a..a3c0bf95fa365 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -172,8 +172,7 @@ Deprecations - Deprecated the methods :meth:`Series.bool` and :meth:`DataFrame.bool` (:issue:`51749`) - Deprecated :meth:`DataFrame.swapaxes` and :meth:`Series.swapaxes`, use :meth:`DataFrame.transpose` or :meth:`Series.transpose` instead (:issue:`51946`) - Deprecated parameter ``convert_type`` in :meth:`Series.apply` (:issue:`52140`) -- Deprecated making :meth:`Series.apply` return a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object. In the future this will return a :class:`Series` whose values are themselves :class:`Series`. - This pattern was very slow and it's recommended to use alternative methods to archive the same goal (:issue:`52116`) +- Deprecated making :meth:`Series.apply` return a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object. In the future this will return a :class:`Series` whose values are themselves :class:`Series`. This pattern was very slow and it's recommended to use alternative methods to archive the same goal (:issue:`52116`) - From d6cb073b0d965d135be27db2d028202c170a2fee Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 6 Apr 2023 08:22:00 +0100 Subject: [PATCH 14/14] fix pre-commit issues --- doc/source/whatsnew/v2.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index a3c0bf95fa365..50d4a8250b005 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -171,8 +171,8 @@ Deprecations - Deprecated logical operations (``|``, ``&``, ``^``) between pandas objects and dtype-less sequences (e.g. ``list``, ``tuple``), wrap a sequence in a :class:`Series` or numpy array before operating instead (:issue:`51521`) - Deprecated the methods :meth:`Series.bool` and :meth:`DataFrame.bool` (:issue:`51749`) - Deprecated :meth:`DataFrame.swapaxes` and :meth:`Series.swapaxes`, use :meth:`DataFrame.transpose` or :meth:`Series.transpose` instead (:issue:`51946`) -- Deprecated parameter ``convert_type`` in :meth:`Series.apply` (:issue:`52140`) - Deprecated making :meth:`Series.apply` return a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object. In the future this will return a :class:`Series` whose values are themselves :class:`Series`. This pattern was very slow and it's recommended to use alternative methods to archive the same goal (:issue:`52116`) +- Deprecated parameter ``convert_type`` in :meth:`Series.apply` (:issue:`52140`) -