Skip to content

Commit 232d84e

Browse files
authored
TST: Use more pytest.importorskip (#54377)
* TST: Use more pytest.importorskip * Fix xml * Final cleanup * Fix condition * Fix downstream * cleanup after matplotlib
1 parent 96ba717 commit 232d84e

30 files changed

+243
-283
lines changed

pandas/tests/arrays/interval/test_interval.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
import pandas.util._test_decorators as td
5-
64
import pandas as pd
75
from pandas import (
86
Index,
@@ -249,12 +247,8 @@ def test_min_max(self, left_right_dtypes, index_or_series_or_array):
249247
# Arrow interaction
250248

251249

252-
pyarrow_skip = td.skip_if_no("pyarrow")
253-
254-
255-
@pyarrow_skip
256250
def test_arrow_extension_type():
257-
import pyarrow as pa
251+
pa = pytest.importorskip("pyarrow")
258252

259253
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
260254

@@ -269,9 +263,8 @@ def test_arrow_extension_type():
269263
assert hash(p1) != hash(p3)
270264

271265

272-
@pyarrow_skip
273266
def test_arrow_array():
274-
import pyarrow as pa
267+
pa = pytest.importorskip("pyarrow")
275268

276269
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
277270

@@ -299,9 +292,8 @@ def test_arrow_array():
299292
pa.array(intervals, type=ArrowIntervalType(pa.float64(), "left"))
300293

301294

302-
@pyarrow_skip
303295
def test_arrow_array_missing():
304-
import pyarrow as pa
296+
pa = pytest.importorskip("pyarrow")
305297

306298
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
307299

@@ -329,14 +321,13 @@ def test_arrow_array_missing():
329321
assert result.storage.equals(expected)
330322

331323

332-
@pyarrow_skip
333324
@pytest.mark.parametrize(
334325
"breaks",
335326
[[0.0, 1.0, 2.0, 3.0], date_range("2017", periods=4, freq="D")],
336327
ids=["float", "datetime64[ns]"],
337328
)
338329
def test_arrow_table_roundtrip(breaks):
339-
import pyarrow as pa
330+
pa = pytest.importorskip("pyarrow")
340331

341332
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
342333

@@ -363,14 +354,13 @@ def test_arrow_table_roundtrip(breaks):
363354
tm.assert_frame_equal(result, expected[0:0])
364355

365356

366-
@pyarrow_skip
367357
@pytest.mark.parametrize(
368358
"breaks",
369359
[[0.0, 1.0, 2.0, 3.0], date_range("2017", periods=4, freq="D")],
370360
ids=["float", "datetime64[ns]"],
371361
)
372362
def test_arrow_table_roundtrip_without_metadata(breaks):
373-
import pyarrow as pa
363+
pa = pytest.importorskip("pyarrow")
374364

375365
arr = IntervalArray.from_breaks(breaks)
376366
arr[1] = None
@@ -386,12 +376,11 @@ def test_arrow_table_roundtrip_without_metadata(breaks):
386376
tm.assert_frame_equal(result, df)
387377

388378

389-
@pyarrow_skip
390379
def test_from_arrow_from_raw_struct_array():
391380
# in case pyarrow lost the Interval extension type (eg on parquet roundtrip
392381
# with datetime64[ns] subtype, see GH-45881), still allow conversion
393382
# from arrow to IntervalArray
394-
import pyarrow as pa
383+
pa = pytest.importorskip("pyarrow")
395384

396385
arr = pa.array([{"left": 0, "right": 1}, {"left": 1, "right": 2}])
397386
dtype = pd.IntervalDtype(np.dtype("int64"), closed="neither")

pandas/tests/arrays/string_/test_string.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import numpy as np
66
import pytest
77

8-
import pandas.util._test_decorators as td
9-
108
from pandas.core.dtypes.common import is_dtype_equal
119

1210
import pandas as pd
@@ -420,10 +418,9 @@ def test_arrow_array(dtype):
420418
assert arr.equals(expected)
421419

422420

423-
@td.skip_if_no("pyarrow")
424421
def test_arrow_roundtrip(dtype, string_storage2):
425422
# roundtrip possible from arrow 1.0.0
426-
import pyarrow as pa
423+
pa = pytest.importorskip("pyarrow")
427424

428425
data = pd.array(["a", "b", None], dtype=dtype)
429426
df = pd.DataFrame({"a": data})
@@ -438,10 +435,9 @@ def test_arrow_roundtrip(dtype, string_storage2):
438435
assert result.loc[2, "a"] is pd.NA
439436

440437

441-
@td.skip_if_no("pyarrow")
442438
def test_arrow_load_from_zero_chunks(dtype, string_storage2):
443439
# GH-41040
444-
import pyarrow as pa
440+
pa = pytest.importorskip("pyarrow")
445441

446442
data = pd.array([], dtype=dtype)
447443
df = pd.DataFrame({"a": data})

pandas/tests/frame/test_api.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
from pandas._config.config import option_context
99

10-
from pandas.util._test_decorators import (
11-
async_mark,
12-
skip_if_no,
13-
)
10+
from pandas.util._test_decorators import async_mark
1411

1512
import pandas as pd
1613
from pandas import (
@@ -373,9 +370,9 @@ def test_constructor_expanddim(self):
373370
with pytest.raises(AttributeError, match=msg):
374371
df._constructor_expanddim(np.arange(27).reshape(3, 3, 3))
375372

376-
@skip_if_no("jinja2")
377373
def test_inspect_getmembers(self):
378374
# GH38740
375+
pytest.importorskip("jinja2")
379376
df = DataFrame()
380377
msg = "DataFrame._data is deprecated"
381378
with tm.assert_produces_warning(

pandas/tests/frame/test_ufunc.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import numpy as np
55
import pytest
66

7-
import pandas.util._test_decorators as td
8-
97
import pandas as pd
108
import pandas._testing as tm
119
from pandas.api.types import is_extension_array_dtype
@@ -247,18 +245,14 @@ def test_alignment_deprecation_enforced():
247245
np.add(s2, df1)
248246

249247

250-
@td.skip_if_no("numba")
251248
def test_alignment_deprecation_many_inputs_enforced():
252249
# Enforced in 2.0
253250
# https://github.com/pandas-dev/pandas/issues/39184
254251
# test that the deprecation also works with > 2 inputs -> using a numba
255252
# written ufunc for this because numpy itself doesn't have such ufuncs
256-
from numba import (
257-
float64,
258-
vectorize,
259-
)
253+
numba = pytest.importorskip("numba")
260254

261-
@vectorize([float64(float64, float64, float64)])
255+
@numba.vectorize([numba.float64(numba.float64, numba.float64, numba.float64)])
262256
def my_ufunc(x, y, z):
263257
return x + y + z
264258

pandas/tests/generic/test_to_xarray.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
import pandas.util._test_decorators as td
5-
64
from pandas import (
75
Categorical,
86
DataFrame,
@@ -12,8 +10,9 @@
1210
)
1311
import pandas._testing as tm
1412

13+
pytest.importorskip("xarray")
14+
1515

16-
@td.skip_if_no("xarray")
1716
class TestDataFrameToXArray:
1817
@pytest.fixture
1918
def df(self):
@@ -84,7 +83,6 @@ def test_to_xarray_with_multiindex(self, df):
8483
tm.assert_frame_equal(result, expected)
8584

8685

87-
@td.skip_if_no("xarray")
8886
class TestSeriesToXArray:
8987
def test_to_xarray_index_types(self, index_flat):
9088
index = index_flat

0 commit comments

Comments
 (0)