From 5aa9bb96bdc8c86a85c5169a99867d0d0dd56900 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 23 Dec 2019 18:50:38 -0800 Subject: [PATCH 1/5] TST: clean up skips and xfails --- pandas/tests/frame/methods/test_rank.py | 14 ++++++++++---- .../tests/indexes/datetimes/test_constructors.py | 9 ++------- pandas/tests/indexes/datetimes/test_tools.py | 6 ++---- pandas/tests/indexes/multi/test_missing.py | 2 +- pandas/tests/io/test_html.py | 2 +- pandas/tests/test_downstream.py | 4 ++++ pandas/tests/window/test_moments.py | 14 +++++--------- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/pandas/tests/frame/methods/test_rank.py b/pandas/tests/frame/methods/test_rank.py index be1a423c22aea..67391fce4b76b 100644 --- a/pandas/tests/frame/methods/test_rank.py +++ b/pandas/tests/frame/methods/test_rank.py @@ -5,6 +5,7 @@ from pandas import DataFrame, Series import pandas.util.testing as tm +import pandas.util._test_decorators as td class TestRank: @@ -26,8 +27,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 + from scipy.stats import rankdata float_frame["A"][::2] = np.nan float_frame["B"][::3] = np.nan @@ -117,8 +120,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 + from scipy.stats import rankdata float_frame["A"][::2] = np.nan float_frame["B"][::3] = np.nan @@ -199,9 +204,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 + 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/io/test_html.py b/pandas/tests/io/test_html.py index bc26615d1aad5..c9ec013fe8c85 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -1175,7 +1175,7 @@ def test_encode(self, html_encoding_file): if is_platform_windows(): if "16" in encoding or "32" in encoding: pytest.skip() - raise + raise def test_parse_failure_unseekable(self): # Issue #17975 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): From 0aaa9fadc69f10c410a251775917938726936f31 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 23 Dec 2019 19:12:43 -0800 Subject: [PATCH 2/5] flake8 fixup --- pandas/tests/frame/methods/test_rank.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/frame/methods/test_rank.py b/pandas/tests/frame/methods/test_rank.py index 67391fce4b76b..91363461d6251 100644 --- a/pandas/tests/frame/methods/test_rank.py +++ b/pandas/tests/frame/methods/test_rank.py @@ -29,7 +29,7 @@ def method(self, request): @td._skip_if_no_scipy def test_rank(self, float_frame): - import scipy.stats + import scipy.stats # noqa:F401 from scipy.stats import rankdata float_frame["A"][::2] = np.nan @@ -122,7 +122,7 @@ def test_rank_mixed_frame(self, float_string_frame): @td._skip_if_no_scipy def test_rank_na_option(self, float_frame): - import scipy.stats + import scipy.stats # noqa:F401 from scipy.stats import rankdata float_frame["A"][::2] = np.nan @@ -206,7 +206,7 @@ def test_rank_axis(self): @td._skip_if_no_scipy def test_rank_methods_frame(self): - import scipy.stats + import scipy.stats # noqa:F401 from scipy.stats import rankdata xs = np.random.randint(0, 21, (100, 26)) From d190226875fea9b15050f19342b402d48e49fec6 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 23 Dec 2019 20:28:56 -0800 Subject: [PATCH 3/5] fix usage --- pandas/tests/frame/methods/test_rank.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/frame/methods/test_rank.py b/pandas/tests/frame/methods/test_rank.py index 91363461d6251..e039cb97e321f 100644 --- a/pandas/tests/frame/methods/test_rank.py +++ b/pandas/tests/frame/methods/test_rank.py @@ -27,7 +27,7 @@ def method(self, request): """ return request.param - @td._skip_if_no_scipy + @td.skip_if_no_scipy def test_rank(self, float_frame): import scipy.stats # noqa:F401 from scipy.stats import rankdata @@ -120,7 +120,7 @@ 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 + @td.skip_if_no_scipy def test_rank_na_option(self, float_frame): import scipy.stats # noqa:F401 from scipy.stats import rankdata @@ -204,7 +204,7 @@ 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 + @td.skip_if_no_scipy def test_rank_methods_frame(self): import scipy.stats # noqa:F401 from scipy.stats import rankdata From 02a3ad8c08af2cfb6c018c883c45d8896cdd053c Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 24 Dec 2019 08:59:11 -0800 Subject: [PATCH 4/5] revert broken --- pandas/tests/io/test_html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/test_html.py b/pandas/tests/io/test_html.py index c9ec013fe8c85..bc26615d1aad5 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -1175,7 +1175,7 @@ def test_encode(self, html_encoding_file): if is_platform_windows(): if "16" in encoding or "32" in encoding: pytest.skip() - raise + raise def test_parse_failure_unseekable(self): # Issue #17975 From 4d3934a6a7cfb00ee1b9c804c0fbed3d3f308dcc Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 24 Dec 2019 09:25:31 -0800 Subject: [PATCH 5/5] isort fixup --- pandas/tests/frame/methods/test_rank.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/frame/methods/test_rank.py b/pandas/tests/frame/methods/test_rank.py index e039cb97e321f..f01a030ad0e22 100644 --- a/pandas/tests/frame/methods/test_rank.py +++ b/pandas/tests/frame/methods/test_rank.py @@ -3,9 +3,10 @@ import numpy as np import pytest +import pandas.util._test_decorators as td + from pandas import DataFrame, Series import pandas.util.testing as tm -import pandas.util._test_decorators as td class TestRank: