Skip to content

Commit

Permalink
TST: suppress deprecation warnings for compress (#22064)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored Aug 15, 2018
1 parent cf70d11 commit 2a2d1cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,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]
Expand Down
16 changes: 9 additions & 7 deletions pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 8 additions & 4 deletions pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2a2d1cf

Please sign in to comment.