Skip to content

Commit 9a8f8a6

Browse files
mroeschkeAlexKirko
authored andcommitted
DEPR: Remove Series.compress (pandas-dev#30514)
1 parent 7bfa883 commit 9a8f8a6

File tree

4 files changed

+1
-73
lines changed

4 files changed

+1
-73
lines changed

doc/source/whatsnew/v1.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
659659
- Changed the default "ordered" argument in :class:`CategoricalDtype` from ``None`` to ``False`` (:issue:`26336`)
660660
- :meth:`Series.set_axis` and :meth:`DataFrame.set_axis` now require "labels" as the first argument and "axis" as an optional named parameter (:issue:`30089`)
661661
- Removed :func:`to_msgpack`, :func:`read_msgpack`, :meth:`DataFrame.to_msgpack`, :meth:`Series.to_msgpack` (:issue:`27103`)
662-
-
662+
- Removed :meth:`Series.compress` (:issue:`21930`)
663663
- Removed the previously deprecated keyword "fill_value" from :meth:`Categorical.fillna`, use "value" instead (:issue:`19269`)
664664
- Removed the previously deprecated keyword "data" from :func:`andrews_curves`, use "frame" instead (:issue:`6956`)
665665
- Removed the previously deprecated keyword "data" from :func:`parallel_coordinates`, use "frame" instead (:issue:`6956`)

pandas/core/series.py

-24
Original file line numberDiff line numberDiff line change
@@ -510,30 +510,6 @@ def ravel(self, order="C"):
510510
"""
511511
return self._values.ravel(order=order)
512512

513-
def compress(self, condition, *args, **kwargs):
514-
"""
515-
Return selected slices of an array along given axis as a Series.
516-
517-
.. deprecated:: 0.24.0
518-
519-
Returns
520-
-------
521-
Series
522-
Series without the slices for which condition is false.
523-
524-
See Also
525-
--------
526-
numpy.ndarray.compress
527-
"""
528-
msg = (
529-
"Series.compress(condition) is deprecated. "
530-
"Use 'Series[condition]' or "
531-
"'np.asarray(series).compress(condition)' instead."
532-
)
533-
warnings.warn(msg, FutureWarning, stacklevel=2)
534-
nv.validate_compress(args, kwargs)
535-
return self[condition]
536-
537513
def __len__(self) -> int:
538514
"""
539515
Return the length of the Series.

pandas/tests/series/test_analytics.py

-24
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,6 @@
1111

1212

1313
class TestSeriesAnalytics:
14-
def test_compress(self):
15-
cond = [True, False, True, False, False]
16-
s = Series([1, -1, 5, 8, 7], index=list("abcde"), name="foo")
17-
expected = Series(s.values.compress(cond), index=list("ac"), name="foo")
18-
with tm.assert_produces_warning(FutureWarning):
19-
result = s.compress(cond)
20-
tm.assert_series_equal(result, expected)
21-
22-
def test_numpy_compress(self):
23-
cond = [True, False, True, False, False]
24-
s = Series([1, -1, 5, 8, 7], index=list("abcde"), name="foo")
25-
expected = Series(s.values.compress(cond), index=list("ac"), name="foo")
26-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
27-
tm.assert_series_equal(np.compress(cond, s), expected)
28-
29-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
30-
msg = "the 'axis' parameter is not supported"
31-
with pytest.raises(ValueError, match=msg):
32-
np.compress(cond, s, axis=1)
33-
34-
msg = "the 'out' parameter is not supported"
35-
with pytest.raises(ValueError, match=msg):
36-
np.compress(cond, s, out=s)
37-
3814
def test_prod_numpy16_bug(self):
3915
s = Series([1.0, 1.0, 1.0], index=range(3))
4016
result = s.prod()

pandas/tests/series/test_api.py

-24
Original file line numberDiff line numberDiff line change
@@ -465,30 +465,6 @@ def f(x):
465465
s = Series(np.random.randn(10))
466466
tm.assert_almost_equal(s.ravel(order="F"), s.values.ravel(order="F"))
467467

468-
# compress
469-
# GH 6658
470-
s = Series([0, 1.0, -1], index=list("abc"))
471-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
472-
result = np.compress(s > 0, s)
473-
tm.assert_series_equal(result, Series([1.0], index=["b"]))
474-
475-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
476-
result = np.compress(s < -1, s)
477-
# result empty Index(dtype=object) as the same as original
478-
exp = Series([], dtype="float64", index=Index([], dtype="object"))
479-
tm.assert_series_equal(result, exp)
480-
481-
s = Series([0, 1.0, -1], index=[0.1, 0.2, 0.3])
482-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
483-
result = np.compress(s > 0, s)
484-
tm.assert_series_equal(result, Series([1.0], index=[0.2]))
485-
486-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
487-
result = np.compress(s < -1, s)
488-
# result empty Float64Index as the same as original
489-
exp = Series([], dtype="float64", index=Index([], dtype="float64"))
490-
tm.assert_series_equal(result, exp)
491-
492468
def test_str_accessor_updates_on_inplace(self):
493469
s = pd.Series(list("abc"))
494470
s.drop([0], inplace=True)

0 commit comments

Comments
 (0)