Skip to content

TST: Use more pytest.importorskip #54377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions pandas/tests/arrays/interval/test_interval.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import pytest

import pandas.util._test_decorators as td

import pandas as pd
from pandas import (
Index,
Expand Down Expand Up @@ -249,12 +247,8 @@ def test_min_max(self, left_right_dtypes, index_or_series_or_array):
# Arrow interaction


pyarrow_skip = td.skip_if_no("pyarrow")


@pyarrow_skip
def test_arrow_extension_type():
import pyarrow as pa
pa = pytest.importorskip("pyarrow")

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

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


@pyarrow_skip
def test_arrow_array():
import pyarrow as pa
pa = pytest.importorskip("pyarrow")

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

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


@pyarrow_skip
def test_arrow_array_missing():
import pyarrow as pa
pa = pytest.importorskip("pyarrow")

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

Expand Down Expand Up @@ -329,14 +321,13 @@ def test_arrow_array_missing():
assert result.storage.equals(expected)


@pyarrow_skip
@pytest.mark.parametrize(
"breaks",
[[0.0, 1.0, 2.0, 3.0], date_range("2017", periods=4, freq="D")],
ids=["float", "datetime64[ns]"],
)
def test_arrow_table_roundtrip(breaks):
import pyarrow as pa
pa = pytest.importorskip("pyarrow")

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

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


@pyarrow_skip
@pytest.mark.parametrize(
"breaks",
[[0.0, 1.0, 2.0, 3.0], date_range("2017", periods=4, freq="D")],
ids=["float", "datetime64[ns]"],
)
def test_arrow_table_roundtrip_without_metadata(breaks):
import pyarrow as pa
pa = pytest.importorskip("pyarrow")

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


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

arr = pa.array([{"left": 0, "right": 1}, {"left": 1, "right": 2}])
dtype = pd.IntervalDtype(np.dtype("int64"), closed="neither")
Expand Down
8 changes: 2 additions & 6 deletions pandas/tests/arrays/string_/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas.core.dtypes.common import is_dtype_equal

import pandas as pd
Expand Down Expand Up @@ -420,10 +418,9 @@ def test_arrow_array(dtype):
assert arr.equals(expected)


@td.skip_if_no("pyarrow")
def test_arrow_roundtrip(dtype, string_storage2):
# roundtrip possible from arrow 1.0.0
import pyarrow as pa
pa = pytest.importorskip("pyarrow")

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


@td.skip_if_no("pyarrow")
def test_arrow_load_from_zero_chunks(dtype, string_storage2):
# GH-41040
import pyarrow as pa
pa = pytest.importorskip("pyarrow")

data = pd.array([], dtype=dtype)
df = pd.DataFrame({"a": data})
Expand Down
7 changes: 2 additions & 5 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

from pandas._config.config import option_context

from pandas.util._test_decorators import (
async_mark,
skip_if_no,
)
from pandas.util._test_decorators import async_mark

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

@skip_if_no("jinja2")
def test_inspect_getmembers(self):
# GH38740
pytest.importorskip("jinja2")
df = DataFrame()
msg = "DataFrame._data is deprecated"
with tm.assert_produces_warning(
Expand Down
10 changes: 2 additions & 8 deletions pandas/tests/frame/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import numpy as np
import pytest

import pandas.util._test_decorators as td

import pandas as pd
import pandas._testing as tm
from pandas.api.types import is_extension_array_dtype
Expand Down Expand Up @@ -247,18 +245,14 @@ def test_alignment_deprecation_enforced():
np.add(s2, df1)


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

@vectorize([float64(float64, float64, float64)])
@numba.vectorize([numba.float64(numba.float64, numba.float64, numba.float64)])
def my_ufunc(x, y, z):
return x + y + z

Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/generic/test_to_xarray.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas import (
Categorical,
DataFrame,
Expand All @@ -12,8 +10,9 @@
)
import pandas._testing as tm

pytest.importorskip("xarray")


@td.skip_if_no("xarray")
class TestDataFrameToXArray:
@pytest.fixture
def df(self):
Expand Down Expand Up @@ -84,7 +83,6 @@ def test_to_xarray_with_multiindex(self, df):
tm.assert_frame_equal(result, expected)


@td.skip_if_no("xarray")
class TestSeriesToXArray:
def test_to_xarray_index_types(self, index_flat):
index = index_flat
Expand Down
Loading