From abc06e32996b1525c1d4ecd4207f1189a039d39f Mon Sep 17 00:00:00 2001 From: gfyoung Date: Tue, 3 Oct 2017 02:19:27 -0700 Subject: [PATCH 1/2] COMPAT: Suppress .take() warning for numpy < 1.12 Follow-up to gh-17352. --- pandas/tests/sparse/test_series.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pandas/tests/sparse/test_series.py b/pandas/tests/sparse/test_series.py index 8c0ed322028e8..16c4baea79bad 100644 --- a/pandas/tests/sparse/test_series.py +++ b/pandas/tests/sparse/test_series.py @@ -9,7 +9,8 @@ import numpy as np import pandas as pd -from pandas import Series, DataFrame, bdate_range, isna, compat +from pandas import (Series, DataFrame, bdate_range, + isna, compat, _np_version_under1p12) from pandas.tseries.offsets import BDay import pandas.util.testing as tm from pandas.compat import range @@ -527,8 +528,13 @@ def test_numpy_take(self): sp = SparseSeries([1.0, 2.0, 3.0]) indices = [1, 2] - tm.assert_series_equal(np.take(sp, indices, axis=0).to_dense(), - np.take(sp.to_dense(), indices, axis=0)) + # gh-17352: older versions of numpy don't properly + # pass in arguments to downstream .take() implementations. + warning = FutureWarning if _np_version_under1p12 else None + + with tm.assert_produces_warning(warning): + tm.assert_series_equal(np.take(sp, indices, axis=0).to_dense(), + np.take(sp.to_dense(), indices, axis=0)) msg = "the 'out' parameter is not supported" tm.assert_raises_regex(ValueError, msg, np.take, From 4f4d1ef7d8da0471fccf4d0cc79c312cf168f91e Mon Sep 17 00:00:00 2001 From: gfyoung Date: Tue, 3 Oct 2017 10:40:23 -0700 Subject: [PATCH 2/2] MAINT: Make tests pass --- pandas/tests/sparse/test_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/sparse/test_series.py b/pandas/tests/sparse/test_series.py index 16c4baea79bad..13dab68b2e5b4 100644 --- a/pandas/tests/sparse/test_series.py +++ b/pandas/tests/sparse/test_series.py @@ -532,7 +532,7 @@ def test_numpy_take(self): # pass in arguments to downstream .take() implementations. warning = FutureWarning if _np_version_under1p12 else None - with tm.assert_produces_warning(warning): + with tm.assert_produces_warning(warning, check_stacklevel=False): tm.assert_series_equal(np.take(sp, indices, axis=0).to_dense(), np.take(sp.to_dense(), indices, axis=0))