From 399e0bcaa606b81da76660f530d4bc65aa7c2f06 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 26 Jul 2018 13:49:41 +0200 Subject: [PATCH 1/4] TST: suppress deprecation warnings for compress --- pandas/tests/series/test_analytics.py | 17 ++++++++++------- pandas/tests/series/test_api.py | 12 ++++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 69969bd090b9b..4d235b4d2178d 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -4,6 +4,7 @@ from itertools import product from distutils.version import LooseVersion import operator +import warnings import pytest from numpy import nan @@ -595,15 +596,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 warnings.catch_warnings(record=True): + 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) From d106215e0fa20fd5465ef7ed78368359b41c8439 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Mon, 13 Aug 2018 14:29:36 +0200 Subject: [PATCH 2/4] update deprecation message --- pandas/core/series.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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] From 396630be5f37c2cd5c94fbc7cdb0ad76603fbc9d Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 14 Aug 2018 12:18:32 +0200 Subject: [PATCH 3/4] try fix py27 --- pandas/tests/series/test_analytics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 167e583cc7ded..e9e6e411203bf 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -599,7 +599,7 @@ def test_numpy_compress(self): with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): tm.assert_series_equal(np.compress(cond, s), expected) - with warnings.catch_warnings(record=True): + 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) From 753929dd2f1445fac7e8ba2172dad270946b1615 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 14 Aug 2018 13:23:07 +0200 Subject: [PATCH 4/4] fix flake8 --- pandas/tests/series/test_analytics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index e9e6e411203bf..6710b90effb2f 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -4,7 +4,6 @@ from itertools import product from distutils.version import LooseVersion import operator -import warnings import pytest from numpy import nan