Skip to content

Commit

Permalink
DEPR: Series.compress (#21930)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger authored and jreback committed Jul 25, 2018
1 parent e0b81d4 commit 693e235
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
5 changes: 5 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 693e235

Please sign in to comment.