Skip to content

Commit 2a2d1cf

Browse files
TST: suppress deprecation warnings for compress (#22064)
1 parent cf70d11 commit 2a2d1cf

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

pandas/core/series.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ def compress(self, condition, *args, **kwargs):
519519
numpy.ndarray.compress
520520
"""
521521
msg = ("Series.compress(condition) is deprecated. "
522-
"Use Series[condition] instead.")
522+
"Use 'Series[condition]' or "
523+
"'np.asarray(series).compress(condition)' instead.")
523524
warnings.warn(msg, FutureWarning, stacklevel=2)
524525
nv.validate_compress(args, kwargs)
525526
return self[condition]

pandas/tests/series/test_analytics.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -595,15 +595,17 @@ def test_numpy_compress(self):
595595
index=list('abcde'), name='foo')
596596
expected = Series(s.values.compress(cond),
597597
index=list('ac'), name='foo')
598-
tm.assert_series_equal(np.compress(cond, s), expected)
598+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
599+
tm.assert_series_equal(np.compress(cond, s), expected)
599600

600-
msg = "the 'axis' parameter is not supported"
601-
tm.assert_raises_regex(ValueError, msg, np.compress,
602-
cond, s, axis=1)
601+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
602+
msg = "the 'axis' parameter is not supported"
603+
tm.assert_raises_regex(ValueError, msg, np.compress,
604+
cond, s, axis=1)
603605

604-
msg = "the 'out' parameter is not supported"
605-
tm.assert_raises_regex(ValueError, msg, np.compress,
606-
cond, s, out=s)
606+
msg = "the 'out' parameter is not supported"
607+
tm.assert_raises_regex(ValueError, msg, np.compress,
608+
cond, s, out=s)
607609

608610
def test_round(self):
609611
self.ts.index.name = "index_name"

pandas/tests/series/test_api.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -424,19 +424,23 @@ def f(x):
424424
# compress
425425
# GH 6658
426426
s = Series([0, 1., -1], index=list('abc'))
427-
result = np.compress(s > 0, s)
427+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
428+
result = np.compress(s > 0, s)
428429
tm.assert_series_equal(result, Series([1.], index=['b']))
429430

430-
result = np.compress(s < -1, s)
431+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
432+
result = np.compress(s < -1, s)
431433
# result empty Index(dtype=object) as the same as original
432434
exp = Series([], dtype='float64', index=Index([], dtype='object'))
433435
tm.assert_series_equal(result, exp)
434436

435437
s = Series([0, 1., -1], index=[.1, .2, .3])
436-
result = np.compress(s > 0, s)
438+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
439+
result = np.compress(s > 0, s)
437440
tm.assert_series_equal(result, Series([1.], index=[.2]))
438441

439-
result = np.compress(s < -1, s)
442+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
443+
result = np.compress(s < -1, s)
440444
# result empty Float64Index as the same as original
441445
exp = Series([], dtype='float64', index=Index([], dtype='float64'))
442446
tm.assert_series_equal(result, exp)

0 commit comments

Comments
 (0)