From 52ae476529add94e0662c03bb87c411dca6db4d3 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Mon, 16 Jul 2018 07:55:54 -0500 Subject: [PATCH 1/2] DEPR: Series.compress --- doc/source/whatsnew/v0.24.0.txt | 2 +- pandas/core/series.py | 5 +++++ pandas/tests/series/test_analytics.py | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 9e3f7ec73f852..d664e348886c3 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -314,7 +314,7 @@ Deprecations - :meth:`DataFrame.to_stata`, :meth:`read_stata`, :class:`StataReader` and :class:`StataWriter` have deprecated the ``encoding`` argument. The encoding of a Stata dta file is determined by the file type and cannot be changed (:issue:`21244`). - :meth:`MultiIndex.to_hierarchical` is deprecated and will be removed in a future version (:issue:`21613`) - :meth:`Series.ptp` is deprecated. Use ``numpy.ptp`` instead (:issue:`21614`) -- +- :meth:`Series.compress` is deprecated. Use ``Series.__getitem__`` instead (:issue:`18262`) .. _whatsnew_0240.prior_deprecations: diff --git a/pandas/core/series.py b/pandas/core/series.py index 0bdb9d9cc23a6..f7f903124b7b8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -513,10 +513,15 @@ def compress(self, condition, *args, **kwargs): """ Return selected slices of an array along given axis as a Series + .. deprecated:: 0.24.0 + See also -------- numpy.ndarray.compress """ + msg = ("Series.compress(condition) is deprecated. " + "Use Series[condition] instead.") + warnings.warn(msg, FutureWarning, stacklevel=2) nv.validate_compress(args, kwargs) return self[condition] diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 28a77bbb1d3fa..b49155f5dc25c 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -585,7 +585,9 @@ def test_compress(self): index=list('abcde'), name='foo') expected = Series(s.values.compress(cond), index=list('ac'), name='foo') - tm.assert_series_equal(s.compress(cond), expected) + with tm.assert_produces_warning(FutureWarning): + result = s.compress(cond) + tm.assert_series_equal(result, expected) def test_numpy_compress(self): cond = [True, False, True, False, False] From c228d494a5348b2483c9d6e27e5eb0c2bac531eb Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 24 Jul 2018 09:53:37 -0500 Subject: [PATCH 2/2] Update whatsnew --- doc/source/whatsnew/v0.24.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 86f3de5417e5c..65dad1304d780 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -382,7 +382,7 @@ Deprecations - :meth:`DataFrame.to_stata`, :meth:`read_stata`, :class:`StataReader` and :class:`StataWriter` have deprecated the ``encoding`` argument. The encoding of a Stata dta file is determined by the file type and cannot be changed (:issue:`21244`). - :meth:`MultiIndex.to_hierarchical` is deprecated and will be removed in a future version (:issue:`21613`) - :meth:`Series.ptp` is deprecated. Use ``numpy.ptp`` instead (:issue:`21614`) -- :meth:`Series.compress` is deprecated. Use ``Series.__getitem__`` instead (:issue:`18262`) +- :meth:`Series.compress` is deprecated. Use ``Series[condition]`` instead (:issue:`18262`) .. _whatsnew_0240.prior_deprecations: