diff --git a/pandas/core/series.py b/pandas/core/series.py index b84179875db1f..15a58afc66b1e 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -518,7 +518,8 @@ def compress(self, condition, *args, **kwargs): numpy.ndarray.compress """ msg = ("Series.compress(condition) is deprecated. " - "Use Series[condition] instead.") + "Use 'Series[condition]' or " + "'np.asarray(series).compress(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 09e89115e120e..6710b90effb2f 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -595,15 +595,17 @@ def test_numpy_compress(self): index=list('abcde'), name='foo') expected = Series(s.values.compress(cond), index=list('ac'), name='foo') - tm.assert_series_equal(np.compress(cond, s), expected) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + tm.assert_series_equal(np.compress(cond, s), expected) - msg = "the 'axis' parameter is not supported" - tm.assert_raises_regex(ValueError, msg, np.compress, - cond, s, axis=1) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + msg = "the 'axis' parameter is not supported" + tm.assert_raises_regex(ValueError, msg, np.compress, + cond, s, axis=1) - msg = "the 'out' parameter is not supported" - tm.assert_raises_regex(ValueError, msg, np.compress, - cond, s, out=s) + msg = "the 'out' parameter is not supported" + tm.assert_raises_regex(ValueError, msg, np.compress, + cond, s, out=s) def test_round(self): self.ts.index.name = "index_name" diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index f7f1ea019a3f0..da9b03e81994d 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -424,19 +424,23 @@ def f(x): # compress # GH 6658 s = Series([0, 1., -1], index=list('abc')) - result = np.compress(s > 0, s) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + result = np.compress(s > 0, s) tm.assert_series_equal(result, Series([1.], index=['b'])) - result = np.compress(s < -1, s) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + result = np.compress(s < -1, s) # result empty Index(dtype=object) as the same as original exp = Series([], dtype='float64', index=Index([], dtype='object')) tm.assert_series_equal(result, exp) s = Series([0, 1., -1], index=[.1, .2, .3]) - result = np.compress(s > 0, s) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + result = np.compress(s > 0, s) tm.assert_series_equal(result, Series([1.], index=[.2])) - result = np.compress(s < -1, s) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + result = np.compress(s < -1, s) # result empty Float64Index as the same as original exp = Series([], dtype='float64', index=Index([], dtype='float64')) tm.assert_series_equal(result, exp)