diff --git a/pandas/tests/computation/test_compat.py b/pandas/tests/computation/test_compat.py index 5e76fa4cbdb4f..cfc08426f84e3 100644 --- a/pandas/tests/computation/test_compat.py +++ b/pandas/tests/computation/test_compat.py @@ -9,36 +9,24 @@ def test_compat(): - # test we have compat with our version of nu + # test we have compat with our version of numexpr from pandas.core.computation.check import NUMEXPR_INSTALLED - try: - import numexpr as ne + ne = pytest.importorskip("numexpr") - ver = ne.__version__ - if Version(ver) < Version(VERSIONS["numexpr"]): - assert not NUMEXPR_INSTALLED - else: - assert NUMEXPR_INSTALLED - except ImportError: - pytest.skip("not testing numexpr version compat") + ver = ne.__version__ + if Version(ver) < Version(VERSIONS["numexpr"]): + assert not NUMEXPR_INSTALLED + else: + assert NUMEXPR_INSTALLED @pytest.mark.parametrize("engine", ENGINES) @pytest.mark.parametrize("parser", expr.PARSERS) def test_invalid_numexpr_version(engine, parser): - def testit(): - a, b = 1, 2 # noqa:F841 - res = pd.eval("a + b", engine=engine, parser=parser) - assert res == 3 - if engine == "numexpr": - try: - import numexpr as ne # noqa:F401 - except ImportError: - pytest.skip("no numexpr") - else: - testit() - else: - testit() + pytest.importorskip("numexpr") + a, b = 1, 2 # noqa:F841 + res = pd.eval("a + b", engine=engine, parser=parser) + assert res == 3 diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 391a3df5233d1..245e54d665745 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -285,16 +285,11 @@ def test_stat_op_api(self, float_frame, float_string_frame): assert_stat_op_api("sem", float_frame, float_string_frame) assert_stat_op_api("median", float_frame, float_string_frame) - try: - from scipy.stats import ( # noqa:F401 - kurtosis, - skew, - ) - - assert_stat_op_api("skew", float_frame, float_string_frame) - assert_stat_op_api("kurt", float_frame, float_string_frame) - except ImportError: - pass + @pytest.mark.filterwarnings("ignore:Dropping of nuisance:FutureWarning") + @td.skip_if_no_scipy + def test_stat_op_api_skew_kurt(self, float_frame, float_string_frame): + assert_stat_op_api("skew", float_frame, float_string_frame) + assert_stat_op_api("kurt", float_frame, float_string_frame) def test_stat_op_calc(self, float_frame_with_na, mixed_float_frame): def count(s): @@ -315,20 +310,6 @@ def std(x): def sem(x): return np.std(x, ddof=1) / np.sqrt(len(x)) - def skewness(x): - from scipy.stats import skew # noqa:F811 - - if len(x) < 3: - return np.nan - return skew(x, bias=False) - - def kurt(x): - from scipy.stats import kurtosis # noqa:F811 - - if len(x) < 4: - return np.nan - return kurtosis(x, bias=False) - assert_stat_op_calc( "nunique", nunique, @@ -371,16 +352,24 @@ def kurt(x): check_dates=True, ) - try: - from scipy import ( # noqa:F401 - kurtosis, - skew, - ) + @td.skip_if_no_scipy + def test_stat_op_calc_skew_kurtosis(self, float_frame_with_na): + def skewness(x): + from scipy.stats import skew + + if len(x) < 3: + return np.nan + return skew(x, bias=False) + + def kurt(x): + from scipy.stats import kurtosis + + if len(x) < 4: + return np.nan + return kurtosis(x, bias=False) - assert_stat_op_calc("skew", skewness, float_frame_with_na) - assert_stat_op_calc("kurt", kurt, float_frame_with_na) - except ImportError: - pass + assert_stat_op_calc("skew", skewness, float_frame_with_na) + assert_stat_op_calc("kurt", kurt, float_frame_with_na) # TODO: Ensure warning isn't emitted in the first place # ignore mean of empty slice and all-NaN