Skip to content

Commit 693e235

Browse files
TomAugspurgerjreback
authored andcommitted
DEPR: Series.compress (pandas-dev#21930)
1 parent e0b81d4 commit 693e235

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ Deprecations
382382
- :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`).
383383
- :meth:`MultiIndex.to_hierarchical` is deprecated and will be removed in a future version (:issue:`21613`)
384384
- :meth:`Series.ptp` is deprecated. Use ``numpy.ptp`` instead (:issue:`21614`)
385-
-
385+
- :meth:`Series.compress` is deprecated. Use ``Series[condition]`` instead (:issue:`18262`)
386386

387387
.. _whatsnew_0240.prior_deprecations:
388388

pandas/core/series.py

+5
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,15 @@ def compress(self, condition, *args, **kwargs):
510510
"""
511511
Return selected slices of an array along given axis as a Series
512512
513+
.. deprecated:: 0.24.0
514+
513515
See also
514516
--------
515517
numpy.ndarray.compress
516518
"""
519+
msg = ("Series.compress(condition) is deprecated. "
520+
"Use Series[condition] instead.")
521+
warnings.warn(msg, FutureWarning, stacklevel=2)
517522
nv.validate_compress(args, kwargs)
518523
return self[condition]
519524

pandas/tests/series/test_analytics.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,9 @@ def test_compress(self):
585585
index=list('abcde'), name='foo')
586586
expected = Series(s.values.compress(cond),
587587
index=list('ac'), name='foo')
588-
tm.assert_series_equal(s.compress(cond), expected)
588+
with tm.assert_produces_warning(FutureWarning):
589+
result = s.compress(cond)
590+
tm.assert_series_equal(result, expected)
589591

590592
def test_numpy_compress(self):
591593
cond = [True, False, True, False, False]

0 commit comments

Comments
 (0)