diff --git a/pandas/tests/frame/methods/test_rank.py b/pandas/tests/frame/methods/test_rank.py index be1a423c22aea..f01a030ad0e22 100644 --- a/pandas/tests/frame/methods/test_rank.py +++ b/pandas/tests/frame/methods/test_rank.py @@ -3,6 +3,8 @@ import numpy as np import pytest +import pandas.util._test_decorators as td + from pandas import DataFrame, Series import pandas.util.testing as tm @@ -26,8 +28,10 @@ def method(self, request): """ return request.param + @td.skip_if_no_scipy def test_rank(self, float_frame): - rankdata = pytest.importorskip("scipy.stats.rankdata") + import scipy.stats # noqa:F401 + from scipy.stats import rankdata float_frame["A"][::2] = np.nan float_frame["B"][::3] = np.nan @@ -117,8 +121,10 @@ def test_rank_mixed_frame(self, float_string_frame): expected = float_string_frame.rank(1, numeric_only=True) tm.assert_frame_equal(result, expected) + @td.skip_if_no_scipy def test_rank_na_option(self, float_frame): - rankdata = pytest.importorskip("scipy.stats.rankdata") + import scipy.stats # noqa:F401 + from scipy.stats import rankdata float_frame["A"][::2] = np.nan float_frame["B"][::3] = np.nan @@ -199,9 +205,10 @@ def test_rank_axis(self): tm.assert_frame_equal(df.rank(axis=0), df.rank(axis="index")) tm.assert_frame_equal(df.rank(axis=1), df.rank(axis="columns")) + @td.skip_if_no_scipy def test_rank_methods_frame(self): - pytest.importorskip("scipy.stats.special") - rankdata = pytest.importorskip("scipy.stats.rankdata") + import scipy.stats # noqa:F401 + from scipy.stats import rankdata xs = np.random.randint(0, 21, (100, 26)) xs = (xs - 10.0) / 10.0 diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index 2f7ed3238b767..58ab44fba08cf 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -725,15 +725,10 @@ def test_constructor_with_int_tz(self, klass, box, tz, dtype): expected = klass([ts]) assert result == expected - # This is the desired future behavior - # Note: this xfail is not strict because the test passes with - # None or any of the UTC variants for tz_naive_fixture - @pytest.mark.xfail(reason="Future behavior", strict=False) - @pytest.mark.filterwarnings("ignore:\\n Passing:FutureWarning") def test_construction_int_rountrip(self, tz_naive_fixture): - # GH 12619 - # TODO(GH-24559): Remove xfail + # GH 12619, GH#24559 tz = tz_naive_fixture + result = 1293858000000000000 expected = DatetimeIndex([result], tz=tz).asi8[0] assert result == expected diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index 6e919571d1423..f1c23d7b245c6 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -720,13 +720,11 @@ def test_to_datetime_utc_true_with_series_datetime_ns(self, cache, date, dtype): tm.assert_series_equal(result, expected) @pytest.mark.parametrize("cache", [True, False]) + @td.skip_if_no("psycopg2") def test_to_datetime_tz_psycopg2(self, cache): # xref 8260 - try: - import psycopg2 - except ImportError: - pytest.skip("no psycopg2 installed") + import psycopg2 # misc cases tz1 = psycopg2.tz.FixedOffsetTimezone(offset=-300, name=None) diff --git a/pandas/tests/indexes/multi/test_missing.py b/pandas/tests/indexes/multi/test_missing.py index 31de40512c474..f053f690e1018 100644 --- a/pandas/tests/indexes/multi/test_missing.py +++ b/pandas/tests/indexes/multi/test_missing.py @@ -101,7 +101,7 @@ def test_nulls(idx): idx.isna() -@pytest.mark.xfail +@pytest.mark.xfail(reason="isna is not defined for MultiIndex") def test_hasnans_isnans(idx): # GH 11343, added tests for hasnans / isnans index = idx.copy() diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index ea128c8c3a422..12d834131f71b 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -55,6 +55,10 @@ def test_oo_optimizable(): @tm.network # Cython import warning @pytest.mark.filterwarnings("ignore:can't:ImportWarning") +@pytest.mark.filterwarnings( + # patsy needs to update their imports + "ignore:Using or importing the ABCs from 'collections:DeprecationWarning" +) def test_statsmodels(): statsmodels = import_module("statsmodels") # noqa diff --git a/pandas/tests/window/test_moments.py b/pandas/tests/window/test_moments.py index 2c65c9e2ac82c..7a6c64d9f9036 100644 --- a/pandas/tests/window/test_moments.py +++ b/pandas/tests/window/test_moments.py @@ -2150,6 +2150,7 @@ def test_rolling_corr_diff_length(self): lambda x: x.rolling(win_type="boxcar", window=10, min_periods=5).mean(), ], ) + @td.skip_if_no_scipy def test_rolling_functions_window_non_shrinkage(self, f): # GH 7764 s = Series(range(4)) @@ -2157,16 +2158,11 @@ def test_rolling_functions_window_non_shrinkage(self, f): df = DataFrame([[1, 5], [3, 2], [3, 9], [-1, 0]], columns=["A", "B"]) df_expected = DataFrame(np.nan, index=df.index, columns=df.columns) - try: - s_result = f(s) - tm.assert_series_equal(s_result, s_expected) - - df_result = f(df) - tm.assert_frame_equal(df_result, df_expected) - except (ImportError): + s_result = f(s) + tm.assert_series_equal(s_result, s_expected) - # scipy needed for rolling_window - pytest.skip("scipy not available") + df_result = f(df) + tm.assert_frame_equal(df_result, df_expected) def test_rolling_functions_window_non_shrinkage_binary(self):