Skip to content

Commit a1405d5

Browse files
jbrockmendelWillAyd
authored andcommitted
TST: clean up skips and xfails (#30441)
1 parent f97a462 commit a1405d5

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

pandas/tests/frame/methods/test_rank.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
import pytest
55

6+
import pandas.util._test_decorators as td
7+
68
from pandas import DataFrame, Series
79
import pandas.util.testing as tm
810

@@ -26,8 +28,10 @@ def method(self, request):
2628
"""
2729
return request.param
2830

31+
@td.skip_if_no_scipy
2932
def test_rank(self, float_frame):
30-
rankdata = pytest.importorskip("scipy.stats.rankdata")
33+
import scipy.stats # noqa:F401
34+
from scipy.stats import rankdata
3135

3236
float_frame["A"][::2] = np.nan
3337
float_frame["B"][::3] = np.nan
@@ -117,8 +121,10 @@ def test_rank_mixed_frame(self, float_string_frame):
117121
expected = float_string_frame.rank(1, numeric_only=True)
118122
tm.assert_frame_equal(result, expected)
119123

124+
@td.skip_if_no_scipy
120125
def test_rank_na_option(self, float_frame):
121-
rankdata = pytest.importorskip("scipy.stats.rankdata")
126+
import scipy.stats # noqa:F401
127+
from scipy.stats import rankdata
122128

123129
float_frame["A"][::2] = np.nan
124130
float_frame["B"][::3] = np.nan
@@ -199,9 +205,10 @@ def test_rank_axis(self):
199205
tm.assert_frame_equal(df.rank(axis=0), df.rank(axis="index"))
200206
tm.assert_frame_equal(df.rank(axis=1), df.rank(axis="columns"))
201207

208+
@td.skip_if_no_scipy
202209
def test_rank_methods_frame(self):
203-
pytest.importorskip("scipy.stats.special")
204-
rankdata = pytest.importorskip("scipy.stats.rankdata")
210+
import scipy.stats # noqa:F401
211+
from scipy.stats import rankdata
205212

206213
xs = np.random.randint(0, 21, (100, 26))
207214
xs = (xs - 10.0) / 10.0

pandas/tests/indexes/datetimes/test_constructors.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -725,15 +725,10 @@ def test_constructor_with_int_tz(self, klass, box, tz, dtype):
725725
expected = klass([ts])
726726
assert result == expected
727727

728-
# This is the desired future behavior
729-
# Note: this xfail is not strict because the test passes with
730-
# None or any of the UTC variants for tz_naive_fixture
731-
@pytest.mark.xfail(reason="Future behavior", strict=False)
732-
@pytest.mark.filterwarnings("ignore:\\n Passing:FutureWarning")
733728
def test_construction_int_rountrip(self, tz_naive_fixture):
734-
# GH 12619
735-
# TODO(GH-24559): Remove xfail
729+
# GH 12619, GH#24559
736730
tz = tz_naive_fixture
731+
737732
result = 1293858000000000000
738733
expected = DatetimeIndex([result], tz=tz).asi8[0]
739734
assert result == expected

pandas/tests/indexes/datetimes/test_tools.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -720,13 +720,11 @@ def test_to_datetime_utc_true_with_series_datetime_ns(self, cache, date, dtype):
720720
tm.assert_series_equal(result, expected)
721721

722722
@pytest.mark.parametrize("cache", [True, False])
723+
@td.skip_if_no("psycopg2")
723724
def test_to_datetime_tz_psycopg2(self, cache):
724725

725726
# xref 8260
726-
try:
727-
import psycopg2
728-
except ImportError:
729-
pytest.skip("no psycopg2 installed")
727+
import psycopg2
730728

731729
# misc cases
732730
tz1 = psycopg2.tz.FixedOffsetTimezone(offset=-300, name=None)

pandas/tests/indexes/multi/test_missing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_nulls(idx):
101101
idx.isna()
102102

103103

104-
@pytest.mark.xfail
104+
@pytest.mark.xfail(reason="isna is not defined for MultiIndex")
105105
def test_hasnans_isnans(idx):
106106
# GH 11343, added tests for hasnans / isnans
107107
index = idx.copy()

pandas/tests/test_downstream.py

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def test_oo_optimizable():
5555
@tm.network
5656
# Cython import warning
5757
@pytest.mark.filterwarnings("ignore:can't:ImportWarning")
58+
@pytest.mark.filterwarnings(
59+
# patsy needs to update their imports
60+
"ignore:Using or importing the ABCs from 'collections:DeprecationWarning"
61+
)
5862
def test_statsmodels():
5963

6064
statsmodels = import_module("statsmodels") # noqa

pandas/tests/window/test_moments.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -2150,23 +2150,19 @@ def test_rolling_corr_diff_length(self):
21502150
lambda x: x.rolling(win_type="boxcar", window=10, min_periods=5).mean(),
21512151
],
21522152
)
2153+
@td.skip_if_no_scipy
21532154
def test_rolling_functions_window_non_shrinkage(self, f):
21542155
# GH 7764
21552156
s = Series(range(4))
21562157
s_expected = Series(np.nan, index=s.index)
21572158
df = DataFrame([[1, 5], [3, 2], [3, 9], [-1, 0]], columns=["A", "B"])
21582159
df_expected = DataFrame(np.nan, index=df.index, columns=df.columns)
21592160

2160-
try:
2161-
s_result = f(s)
2162-
tm.assert_series_equal(s_result, s_expected)
2163-
2164-
df_result = f(df)
2165-
tm.assert_frame_equal(df_result, df_expected)
2166-
except (ImportError):
2161+
s_result = f(s)
2162+
tm.assert_series_equal(s_result, s_expected)
21672163

2168-
# scipy needed for rolling_window
2169-
pytest.skip("scipy not available")
2164+
df_result = f(df)
2165+
tm.assert_frame_equal(df_result, df_expected)
21702166

21712167
def test_rolling_functions_window_non_shrinkage_binary(self):
21722168

0 commit comments

Comments
 (0)