Skip to content

Commit 4ff4056

Browse files
committed
simplify skip_platform
1 parent e5f7138 commit 4ff4056

File tree

4 files changed

+29
-40
lines changed

4 files changed

+29
-40
lines changed

tests/__init__.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
from __future__ import annotations
22

3-
from collections.abc import Callable
43
from contextlib import (
54
AbstractContextManager,
65
nullcontext,
76
suppress,
87
)
98
import os
109
import platform
10+
import sys
1111
from typing import (
1212
TYPE_CHECKING,
13-
Any,
1413
Final,
1514
Literal,
1615
TypeAlias,
@@ -466,6 +465,7 @@
466465

467466
TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
468467
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()
468+
MAC_ARM = sys.platform == "darwin" and platform.processor() == "arm64"
469469
PD_LTE_23 = Version(pd.__version__) < Version("2.3.999")
470470
NUMPY20 = np.lib.NumpyVersion(np.__version__) >= "2.0.0"
471471

@@ -671,13 +671,5 @@ def pytest_warns_bounded(
671671
return suppress(upper_exception)
672672

673673

674-
def skip_platform(
675-
raise_type_error: Callable[[], Any], dtype: type | str | ExtensionDtype
676-
) -> None:
677-
system = platform.system()
678-
if (
679-
system == "Windows" or system == "Darwin" and platform.processor() == "arm"
680-
) and dtype in {"f16", "float128"}:
681-
with pytest.raises(TypeError):
682-
raise_type_error()
683-
pytest.skip(f"{system} does not support {dtype}")
674+
def skip_platform(dtype: type | str | ExtensionDtype) -> bool:
675+
return (WINDOWS or MAC_ARM) and dtype in {"f16", "float128"}

tests/arrays/test_floating_array.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ def test_constructor() -> None:
3232

3333
@pytest.mark.parametrize(("dtype", "target_dtype"), PANDAS_FLOAT_ARGS.items(), ids=repr)
3434
def test_constructor_dtype(dtype: PandasFloatDtypeArg, target_dtype: type) -> None:
35-
def maker() -> FloatingArray:
36-
return assert_type(pd.array([1.0], dtype=dtype), FloatingArray)
37-
38-
skip_platform(maker, dtype)
39-
40-
check(maker(), FloatingArray, target_dtype)
35+
if skip_platform(dtype):
36+
with pytest.raises(TypeError):
37+
assert_type(pd.array([1.0], dtype=dtype), FloatingArray)
38+
else:
39+
check(pd.array([1.0], dtype=dtype), FloatingArray, target_dtype)
4140

4241
if TYPE_CHECKING:
4342
# pandas Float32

tests/indexes/test_index_float.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,11 @@ def test_constructor() -> None:
5252
def test_constructor_dtype(
5353
dtype: "FloatNotNumpy16DtypeArg", target_dtype: type
5454
) -> None:
55-
def maker() -> "pd.Index[float]":
56-
return assert_type(pd.Index([1.0], dtype=dtype), "pd.Index[float]")
57-
58-
skip_platform(maker, dtype)
59-
if target_dtype is np.float16:
60-
reason = r"float16 indexes are not supported"
61-
with pytest.raises(NotImplementedError, match=reason):
62-
maker()
63-
pytest.skip(reason)
64-
65-
check(maker(), pd.Index, target_dtype)
55+
if skip_platform(dtype):
56+
with pytest.raises(TypeError):
57+
assert_type(pd.Index([1.0], dtype=dtype), "pd.Index[float]")
58+
else:
59+
check(pd.Index([1.0], dtype=dtype), pd.Index, target_dtype)
6660

6761
if TYPE_CHECKING:
6862
# python float
@@ -116,9 +110,11 @@ def test_astype_float(
116110
) -> None:
117111
s = pd.Index([1, 2, 3])
118112

119-
skip_platform(lambda: s.astype(cast_arg), cast_arg)
120-
121-
check(s.astype(cast_arg), pd.Index, target_type)
113+
if skip_platform(cast_arg):
114+
with pytest.raises(TypeError):
115+
assert_type(s.astype(cast_arg), "pd.Index[float]")
116+
else:
117+
check(s.astype(cast_arg), pd.Index, target_type)
122118

123119
if TYPE_CHECKING:
124120
# python float

tests/series/test_series_float.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ def test_constructor() -> None:
4646

4747
@pytest.mark.parametrize(("dtype", "target_dtype"), TYPE_FLOAT_ARGS.items())
4848
def test_constructor_dtype(dtype: FloatDtypeArg, target_dtype: type) -> None:
49-
def maker() -> "pd.Series[float]":
50-
return assert_type(pd.Series([1.0], dtype=dtype), "pd.Series[float]")
49+
if skip_platform(dtype):
50+
with pytest.raises(TypeError):
51+
assert_type(pd.Series([1.0], dtype=dtype), "pd.Series[float]")
52+
else:
53+
check(pd.Series([1.0], dtype=dtype), pd.Series, target_dtype)
5154

52-
skip_platform(maker, dtype)
53-
54-
check(maker(), pd.Series, target_dtype)
5555
if TYPE_CHECKING:
5656
# python float
5757
assert_type(pd.Series([1.0], dtype=float), "pd.Series[float]")
@@ -102,9 +102,11 @@ def test_astype_float(
102102
) -> None:
103103
s = pd.Series([1, 2, 3])
104104

105-
skip_platform(lambda: s.astype(cast_arg), cast_arg)
106-
107-
check(s.astype(cast_arg), pd.Series, target_type)
105+
if skip_platform(cast_arg):
106+
with pytest.raises(TypeError):
107+
assert_type(s.astype(cast_arg), "pd.Series[float]")
108+
else:
109+
check(s.astype(cast_arg), pd.Series, target_type)
108110

109111
if TYPE_CHECKING:
110112
# python float

0 commit comments

Comments
 (0)