From 693e2353175592e9cb0e11be8d087541b17bda71 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Wed, 25 Jul 2018 05:31:37 -0500 Subject: [PATCH] DEPR: Series.compress (#21930) --- 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 8cb384f50d371..06498b28cb77b 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[condition]`` instead (:issue:`18262`) .. _whatsnew_0240.prior_deprecations: diff --git a/pandas/core/series.py b/pandas/core/series.py index 03fc9701de1fc..d4c11b19082ab 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -510,10 +510,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 8c0f4b11149fe..69969bd090b9b 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]