From 83331467cb0f40b5381fc945a172ae98fcfcd4e3 Mon Sep 17 00:00:00 2001 From: phofl Date: Wed, 1 Apr 2020 19:32:58 +0200 Subject: [PATCH 01/10] Start deprecating squeeze option in groupby --- pandas/core/frame.py | 15 ++++++++++++--- pandas/core/groupby/generic.py | 25 ------------------------- pandas/core/groupby/groupby.py | 4 ---- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 8ada8e830b834..e84f1f3c5244a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5818,11 +5818,20 @@ def groupby( ) -> "DataFrameGroupBy": from pandas.core.groupby.generic import DataFrameGroupBy + if squeeze is not False: + warnings.warn( + ( + "The `squeeze` parameter in pd.groupby is deprecated and " + "will be removed in a future version." + ), + FutureWarning, + stacklevel=2, + ) + if level is None and by is None: raise TypeError("You have to supply one of 'by' and 'level'") axis = self._get_axis_number(axis) - - return DataFrameGroupBy( + grouped = DataFrameGroupBy( obj=self, keys=by, axis=axis, @@ -5830,9 +5839,9 @@ def groupby( as_index=as_index, sort=sort, group_keys=group_keys, - squeeze=squeeze, observed=observed, ) + return grouped _shared_docs[ "pivot" diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 093c925acbc49..3a231e99f0bd0 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1257,31 +1257,6 @@ def first_not_none(values): all_indexed_same = all_indexes_same([x.index for x in values]) singular_series = len(values) == 1 and applied_index.nlevels == 1 - # GH3596 - # provide a reduction (Frame -> Series) if groups are - # unique - if self.squeeze: - # assign the name to this series - if singular_series: - values[0].name = keys[0] - - # GH2893 - # we have series in the values array, we want to - # produce a series: - # if any of the sub-series are not indexed the same - # OR we don't have a multi-index and we have only a - # single values - return self._concat_objects( - keys, values, not_indexed_same=not_indexed_same - ) - - # still a series - # path added as of GH 5545 - elif all_indexed_same: - from pandas.core.reshape.concat import concat - - return concat(values) - if not all_indexed_same: # GH 8467 return self._concat_objects(keys, values, not_indexed_same=True) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index ebdb0062491be..69690a47e42d1 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -369,7 +369,6 @@ def __init__( as_index: bool = True, sort: bool = True, group_keys: bool = True, - squeeze: bool = False, observed: bool = False, mutated: bool = False, ): @@ -391,7 +390,6 @@ def __init__( self.keys = keys self.sort = sort self.group_keys = group_keys - self.squeeze = squeeze self.observed = observed self.mutated = mutated @@ -2521,7 +2519,6 @@ def get_groupby( as_index: bool = True, sort: bool = True, group_keys: bool = True, - squeeze: bool = False, observed: bool = False, mutated: bool = False, ) -> GroupBy: @@ -2549,7 +2546,6 @@ def get_groupby( as_index=as_index, sort=sort, group_keys=group_keys, - squeeze=squeeze, observed=observed, mutated=mutated, ) From 5b58008888980e07d6526aa2cdf4fbe20e31543f Mon Sep 17 00:00:00 2001 From: phofl Date: Wed, 1 Apr 2020 21:53:47 +0200 Subject: [PATCH 02/10] Deprecate squeeze option --- doc/source/whatsnew/v1.1.0.rst | 1 + pandas/core/frame.py | 5 ++-- pandas/core/generic.py | 2 ++ pandas/core/resample.py | 1 - pandas/core/series.py | 14 +++++++++-- pandas/tests/groupby/test_groupby.py | 37 +++++++++++++++++++++++++--- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 8db837a38170b..894c61d279cb6 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -254,6 +254,7 @@ Deprecations - :meth:`DataFrame.to_dict` has deprecated accepting short names for ``orient`` in future versions (:issue:`32515`) - :meth:`Categorical.to_dense` is deprecated and will be removed in a future version, use ``np.asarray(cat)`` instead (:issue:`32639`) - The ``fastpath`` keyword in the ``SingleBlockManager`` constructor is deprecated and will be removed in a future version (:issue:`33092`) +- The ``squeeze`` keyword in the ``groupby``function is deprecated and will be removed in a future version (:issue:`32980`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e84f1f3c5244a..79fc60d40772a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -40,6 +40,7 @@ from pandas._config import get_option from pandas._libs import algos as libalgos, lib, properties +from pandas._libs.lib import no_default from pandas._typing import Axes, Axis, Dtype, FilePathOrBuffer, Label, Level, Renamer from pandas.compat import PY37 from pandas.compat._optional import import_optional_dependency @@ -5813,12 +5814,12 @@ def groupby( as_index: bool = True, sort: bool = True, group_keys: bool = True, - squeeze: bool = False, + squeeze: bool = no_default, observed: bool = False, ) -> "DataFrameGroupBy": from pandas.core.groupby.generic import DataFrameGroupBy - if squeeze is not False: + if squeeze is not no_default: warnings.warn( ( "The `squeeze` parameter in pd.groupby is deprecated and " diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 62f5419c1f4c8..651b3ef99452b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7419,6 +7419,8 @@ def clip( squeeze : bool, default False Reduce the dimensionality of the return type if possible, otherwise return a consistent type. + deprecated:: 1.1.0 + observed : bool, default False This only applies if any of the groupers are Categoricals. If True: only show observed values for categorical groupers. diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 9e3318db3cfb9..3b34dd7c06cee 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -76,7 +76,6 @@ def __init__(self, obj, groupby=None, axis=0, kind=None, **kwargs): self.sort = True self.axis = axis self.kind = kind - self.squeeze = False self.group_keys = True self.as_index = True self.exclusions = set() diff --git a/pandas/core/series.py b/pandas/core/series.py index 7e575bf9e6115..106f4693f9cf8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -22,6 +22,7 @@ from pandas._config import get_option from pandas._libs import lib, properties, reshape, tslibs +from pandas._libs.lib import no_default from pandas._typing import Axis, DtypeObj, Label from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution, doc @@ -1646,11 +1647,21 @@ def groupby( as_index: bool = True, sort: bool = True, group_keys: bool = True, - squeeze: bool = False, + squeeze: bool = no_default, observed: bool = False, ) -> "SeriesGroupBy": from pandas.core.groupby.generic import SeriesGroupBy + if squeeze is not no_default: + warnings.warn( + ( + "The `squeeze` parameter in pd.groupby is deprecated and " + "will be removed in a future version." + ), + FutureWarning, + stacklevel=2, + ) + if level is None and by is None: raise TypeError("You have to supply one of 'by' and 'level'") axis = self._get_axis_number(axis) @@ -1663,7 +1674,6 @@ def groupby( as_index=as_index, sort=sort, group_keys=group_keys, - squeeze=squeeze, observed=observed, ) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index b8d8f56512a69..4aaf68e36b673 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -94,6 +94,11 @@ def max_value(group): tm.assert_series_equal(result, expected) +@pytest.mark.xfail( + reason="GH#32380; the squeeze option will be " + "deprecated, so the DataFrame won't be converted " + "to a Series." +) def test_groupby_return_type(): # GH2893, return a reduced type @@ -109,7 +114,8 @@ def test_groupby_return_type(): def func(dataf): return dataf["val2"] - dataf["val2"].mean() - result = df1.groupby("val1", squeeze=True).apply(func) + with tm.assert_produces_warning(FutureWarning): + result = df1.groupby("val1", squeeze=True).apply(func) assert isinstance(result, Series) df2 = DataFrame( @@ -124,12 +130,14 @@ def func(dataf): def func(dataf): return dataf["val2"] - dataf["val2"].mean() - result = df2.groupby("val1", squeeze=True).apply(func) + with tm.assert_produces_warning(FutureWarning): + result = df2.groupby("val1", squeeze=True).apply(func) assert isinstance(result, Series) # GH3596, return a consistent type (regression in 0.11 from 0.10.1) df = DataFrame([[1, 1], [1, 1]], columns=["X", "Y"]) - result = df.groupby("X", squeeze=False).count() + with tm.assert_produces_warning(FutureWarning): + result = df.groupby("X", squeeze=False).count() assert isinstance(result, DataFrame) @@ -2057,3 +2065,26 @@ def test_groups_repr_truncates(max_seq_items, expected): result = df.groupby(np.array(df.a)).groups.__repr__() assert result == expected + + +@pytest.mark.parametrize("param", [True, False]) +def test_groupy_squeeze_is_deprecated(param): + # GH 32380: Deprecate the squeeze option in groupby + df = DataFrame( + [ + {"val1": 1, "val2": 20}, + {"val1": 1, "val2": 19}, + {"val1": 1, "val2": 27}, + {"val1": 1, "val2": 12}, + ] + ) + + def func(dataf): + return dataf["val2"] - dataf["val2"].mean() + + with tm.assert_produces_warning(FutureWarning): + result = df.groupby("val1", squeeze=param).apply(func) + assert isinstance(result, DataFrame) + + with tm.assert_produces_warning(FutureWarning): + df["val1"].groupby(["a", "b", "a", "b"], squeeze=False) From 625254ff8f96c8c67f7454182b55daabb0089565 Mon Sep 17 00:00:00 2001 From: phofl Date: Wed, 1 Apr 2020 21:54:18 +0200 Subject: [PATCH 03/10] Change issue number in whats new --- doc/source/whatsnew/v1.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 894c61d279cb6..b4d0b312026dc 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -254,7 +254,7 @@ Deprecations - :meth:`DataFrame.to_dict` has deprecated accepting short names for ``orient`` in future versions (:issue:`32515`) - :meth:`Categorical.to_dense` is deprecated and will be removed in a future version, use ``np.asarray(cat)`` instead (:issue:`32639`) - The ``fastpath`` keyword in the ``SingleBlockManager`` constructor is deprecated and will be removed in a future version (:issue:`33092`) -- The ``squeeze`` keyword in the ``groupby``function is deprecated and will be removed in a future version (:issue:`32980`) +- The ``squeeze`` keyword in the ``groupby``function is deprecated and will be removed in a future version (:issue:`32380`) .. --------------------------------------------------------------------------- From b6f99ce28fdd716c057f7a00f390912153f635a6 Mon Sep 17 00:00:00 2001 From: phofl Date: Wed, 1 Apr 2020 21:58:52 +0200 Subject: [PATCH 04/10] Run flake diff --- pandas/core/generic.py | 2 +- pandas/core/groupby/generic.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 651b3ef99452b..c2ceb54d44116 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7420,7 +7420,7 @@ def clip( Reduce the dimensionality of the return type if possible, otherwise return a consistent type. deprecated:: 1.1.0 - + observed : bool, default False This only applies if any of the groupers are Categoricals. If True: only show observed values for categorical groupers. diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 3a231e99f0bd0..2c9dceb041dbd 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1253,9 +1253,7 @@ def first_not_none(values): if isinstance(v, (np.ndarray, Index, Series)): if isinstance(v, Series): - applied_index = self._selected_obj._get_axis(self.axis) all_indexed_same = all_indexes_same([x.index for x in values]) - singular_series = len(values) == 1 and applied_index.nlevels == 1 if not all_indexed_same: # GH 8467 From afb14e42c2ae209a136b851984ee467f98f4cf31 Mon Sep 17 00:00:00 2001 From: phofl Date: Wed, 1 Apr 2020 22:44:37 +0200 Subject: [PATCH 05/10] Fix sphinx inline issue --- doc/source/whatsnew/v1.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index b4d0b312026dc..91ecb4fc7893a 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -254,7 +254,7 @@ Deprecations - :meth:`DataFrame.to_dict` has deprecated accepting short names for ``orient`` in future versions (:issue:`32515`) - :meth:`Categorical.to_dense` is deprecated and will be removed in a future version, use ``np.asarray(cat)`` instead (:issue:`32639`) - The ``fastpath`` keyword in the ``SingleBlockManager`` constructor is deprecated and will be removed in a future version (:issue:`33092`) -- The ``squeeze`` keyword in the ``groupby``function is deprecated and will be removed in a future version (:issue:`32380`) +- The ``squeeze`` keyword in the ``groupby`` function is deprecated and will be removed in a future version (:issue:`32380`) .. --------------------------------------------------------------------------- From b1210ead48b4c17489c696c486ed202f5c141c72 Mon Sep 17 00:00:00 2001 From: phofl Date: Thu, 2 Apr 2020 21:25:19 +0200 Subject: [PATCH 06/10] Revert Changes and add only FutureWarnining --- doc/source/whatsnew/v1.1.0.rst | 1 - pandas/core/frame.py | 9 ++++++--- pandas/core/generic.py | 5 +++-- pandas/core/groupby/generic.py | 27 +++++++++++++++++++++++++++ pandas/core/groupby/groupby.py | 4 ++++ pandas/core/resample.py | 1 + pandas/core/series.py | 5 ++++- pandas/tests/groupby/test_groupby.py | 28 ---------------------------- 8 files changed, 45 insertions(+), 35 deletions(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 91ecb4fc7893a..8db837a38170b 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -254,7 +254,6 @@ Deprecations - :meth:`DataFrame.to_dict` has deprecated accepting short names for ``orient`` in future versions (:issue:`32515`) - :meth:`Categorical.to_dense` is deprecated and will be removed in a future version, use ``np.asarray(cat)`` instead (:issue:`32639`) - The ``fastpath`` keyword in the ``SingleBlockManager`` constructor is deprecated and will be removed in a future version (:issue:`33092`) -- The ``squeeze`` keyword in the ``groupby`` function is deprecated and will be removed in a future version (:issue:`32380`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 79fc60d40772a..b12a0daaad642 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -36,11 +36,11 @@ import numpy as np import numpy.ma as ma +from pandas._libs.lib import no_default from pandas._config import get_option from pandas._libs import algos as libalgos, lib, properties -from pandas._libs.lib import no_default from pandas._typing import Axes, Axis, Dtype, FilePathOrBuffer, Label, Level, Renamer from pandas.compat import PY37 from pandas.compat._optional import import_optional_dependency @@ -5828,11 +5828,14 @@ def groupby( FutureWarning, stacklevel=2, ) + else: + squeeze = False if level is None and by is None: raise TypeError("You have to supply one of 'by' and 'level'") axis = self._get_axis_number(axis) - grouped = DataFrameGroupBy( + + return DataFrameGroupBy( obj=self, keys=by, axis=axis, @@ -5840,9 +5843,9 @@ def groupby( as_index=as_index, sort=sort, group_keys=group_keys, + squeeze=squeeze, observed=observed, ) - return grouped _shared_docs[ "pivot" diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c2ceb54d44116..a0437142c0ad2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7419,8 +7419,9 @@ def clip( squeeze : bool, default False Reduce the dimensionality of the return type if possible, otherwise return a consistent type. - deprecated:: 1.1.0 - + + deprecated:: 2.0 + observed : bool, default False This only applies if any of the groupers are Categoricals. If True: only show observed values for categorical groupers. diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 2c9dceb041dbd..093c925acbc49 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1253,7 +1253,34 @@ def first_not_none(values): if isinstance(v, (np.ndarray, Index, Series)): if isinstance(v, Series): + applied_index = self._selected_obj._get_axis(self.axis) all_indexed_same = all_indexes_same([x.index for x in values]) + singular_series = len(values) == 1 and applied_index.nlevels == 1 + + # GH3596 + # provide a reduction (Frame -> Series) if groups are + # unique + if self.squeeze: + # assign the name to this series + if singular_series: + values[0].name = keys[0] + + # GH2893 + # we have series in the values array, we want to + # produce a series: + # if any of the sub-series are not indexed the same + # OR we don't have a multi-index and we have only a + # single values + return self._concat_objects( + keys, values, not_indexed_same=not_indexed_same + ) + + # still a series + # path added as of GH 5545 + elif all_indexed_same: + from pandas.core.reshape.concat import concat + + return concat(values) if not all_indexed_same: # GH 8467 diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 69690a47e42d1..ebdb0062491be 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -369,6 +369,7 @@ def __init__( as_index: bool = True, sort: bool = True, group_keys: bool = True, + squeeze: bool = False, observed: bool = False, mutated: bool = False, ): @@ -390,6 +391,7 @@ def __init__( self.keys = keys self.sort = sort self.group_keys = group_keys + self.squeeze = squeeze self.observed = observed self.mutated = mutated @@ -2519,6 +2521,7 @@ def get_groupby( as_index: bool = True, sort: bool = True, group_keys: bool = True, + squeeze: bool = False, observed: bool = False, mutated: bool = False, ) -> GroupBy: @@ -2546,6 +2549,7 @@ def get_groupby( as_index=as_index, sort=sort, group_keys=group_keys, + squeeze=squeeze, observed=observed, mutated=mutated, ) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 3b34dd7c06cee..9e3318db3cfb9 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -76,6 +76,7 @@ def __init__(self, obj, groupby=None, axis=0, kind=None, **kwargs): self.sort = True self.axis = axis self.kind = kind + self.squeeze = False self.group_keys = True self.as_index = True self.exclusions = set() diff --git a/pandas/core/series.py b/pandas/core/series.py index 106f4693f9cf8..44a14925cc178 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -18,11 +18,11 @@ import warnings import numpy as np +from pandas._libs.lib import no_default from pandas._config import get_option from pandas._libs import lib, properties, reshape, tslibs -from pandas._libs.lib import no_default from pandas._typing import Axis, DtypeObj, Label from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution, doc @@ -1661,6 +1661,8 @@ def groupby( FutureWarning, stacklevel=2, ) + else: + squeeze = False if level is None and by is None: raise TypeError("You have to supply one of 'by' and 'level'") @@ -1674,6 +1676,7 @@ def groupby( as_index=as_index, sort=sort, group_keys=group_keys, + squeeze=squeeze, observed=observed, ) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 4aaf68e36b673..6394484d338e0 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -94,11 +94,6 @@ def max_value(group): tm.assert_series_equal(result, expected) -@pytest.mark.xfail( - reason="GH#32380; the squeeze option will be " - "deprecated, so the DataFrame won't be converted " - "to a Series." -) def test_groupby_return_type(): # GH2893, return a reduced type @@ -2065,26 +2060,3 @@ def test_groups_repr_truncates(max_seq_items, expected): result = df.groupby(np.array(df.a)).groups.__repr__() assert result == expected - - -@pytest.mark.parametrize("param", [True, False]) -def test_groupy_squeeze_is_deprecated(param): - # GH 32380: Deprecate the squeeze option in groupby - df = DataFrame( - [ - {"val1": 1, "val2": 20}, - {"val1": 1, "val2": 19}, - {"val1": 1, "val2": 27}, - {"val1": 1, "val2": 12}, - ] - ) - - def func(dataf): - return dataf["val2"] - dataf["val2"].mean() - - with tm.assert_produces_warning(FutureWarning): - result = df.groupby("val1", squeeze=param).apply(func) - assert isinstance(result, DataFrame) - - with tm.assert_produces_warning(FutureWarning): - df["val1"].groupby(["a", "b", "a", "b"], squeeze=False) From 645094073ee7578f2e60f5765a0059d62ece4bb2 Mon Sep 17 00:00:00 2001 From: phofl Date: Thu, 2 Apr 2020 21:32:50 +0200 Subject: [PATCH 07/10] Delte whitespaces in empty line (PEP8) --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a0437142c0ad2..4625378c8a208 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7419,9 +7419,9 @@ def clip( squeeze : bool, default False Reduce the dimensionality of the return type if possible, otherwise return a consistent type. - + deprecated:: 2.0 - + observed : bool, default False This only applies if any of the groupers are Categoricals. If True: only show observed values for categorical groupers. From 0eae720d32739ced0484f79d8f24d26d81f79c64 Mon Sep 17 00:00:00 2001 From: phofl Date: Thu, 2 Apr 2020 22:43:49 +0200 Subject: [PATCH 08/10] Resort input statements --- pandas/core/frame.py | 2 +- pandas/core/series.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b12a0daaad642..4e230c7b4c31c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -36,11 +36,11 @@ import numpy as np import numpy.ma as ma -from pandas._libs.lib import no_default from pandas._config import get_option from pandas._libs import algos as libalgos, lib, properties +from pandas._libs.lib import no_default from pandas._typing import Axes, Axis, Dtype, FilePathOrBuffer, Label, Level, Renamer from pandas.compat import PY37 from pandas.compat._optional import import_optional_dependency diff --git a/pandas/core/series.py b/pandas/core/series.py index 44a14925cc178..7a72a6b0a1875 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -18,11 +18,11 @@ import warnings import numpy as np -from pandas._libs.lib import no_default from pandas._config import get_option from pandas._libs import lib, properties, reshape, tslibs +from pandas._libs.lib import no_default from pandas._typing import Axis, DtypeObj, Label from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution, doc From 9cad0afa4d9cf92869f8b7edae4db94e151f3a92 Mon Sep 17 00:00:00 2001 From: phofl Date: Fri, 3 Apr 2020 09:07:59 +0200 Subject: [PATCH 09/10] Change comments in Warning and add whats new --- doc/source/whatsnew/v1.1.0.rst | 1 + pandas/core/frame.py | 2 +- pandas/core/generic.py | 2 +- pandas/core/series.py | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 8db837a38170b..91ecb4fc7893a 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -254,6 +254,7 @@ Deprecations - :meth:`DataFrame.to_dict` has deprecated accepting short names for ``orient`` in future versions (:issue:`32515`) - :meth:`Categorical.to_dense` is deprecated and will be removed in a future version, use ``np.asarray(cat)`` instead (:issue:`32639`) - The ``fastpath`` keyword in the ``SingleBlockManager`` constructor is deprecated and will be removed in a future version (:issue:`33092`) +- The ``squeeze`` keyword in the ``groupby`` function is deprecated and will be removed in a future version (:issue:`32380`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 4e230c7b4c31c..97c80d635cda5 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5822,7 +5822,7 @@ def groupby( if squeeze is not no_default: warnings.warn( ( - "The `squeeze` parameter in pd.groupby is deprecated and " + "The `squeeze` parameter is deprecated and " "will be removed in a future version." ), FutureWarning, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4625378c8a208..2a38180c9b501 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7420,7 +7420,7 @@ def clip( Reduce the dimensionality of the return type if possible, otherwise return a consistent type. - deprecated:: 2.0 + deprecated:: 1.1.0 observed : bool, default False This only applies if any of the groupers are Categoricals. diff --git a/pandas/core/series.py b/pandas/core/series.py index 7a72a6b0a1875..522370674414b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1655,7 +1655,7 @@ def groupby( if squeeze is not no_default: warnings.warn( ( - "The `squeeze` parameter in pd.groupby is deprecated and " + "The `squeeze` parameter is deprecated and " "will be removed in a future version." ), FutureWarning, From 16c7058dda0123463273d49d265603c2fd810971 Mon Sep 17 00:00:00 2001 From: patrick <61934744+phofl@users.noreply.github.com> Date: Sun, 19 Apr 2020 23:12:24 +0200 Subject: [PATCH 10/10] Add newline before deprecated comment Co-Authored-By: William Ayd --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2a38180c9b501..ebc43ea2e0891 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7420,7 +7420,7 @@ def clip( Reduce the dimensionality of the return type if possible, otherwise return a consistent type. - deprecated:: 1.1.0 + .. deprecated:: 1.1.0 observed : bool, default False This only applies if any of the groupers are Categoricals.