Skip to content

Commit cc784d1

Browse files
committed
simplify skip_platform
1 parent f87938d commit cc784d1

File tree

4 files changed

+28
-40
lines changed

4 files changed

+28
-40
lines changed

tests/__init__.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from collections.abc import Callable
43
from contextlib import (
54
AbstractContextManager,
65
nullcontext,
@@ -10,7 +9,6 @@
109
import sys
1110
from typing import (
1211
TYPE_CHECKING,
13-
Any,
1412
Final,
1513
Literal,
1614
TypeAlias,
@@ -468,6 +466,7 @@
468466
LINUX = sys.platform == "linux"
469467
WINDOWS = sys.platform in {"win32", "cygwin"}
470468
MAC = sys.platform == "darwin"
469+
MAC_ARM = sys.platform == "darwin" and platform.processor() == "arm64"
471470
PD_LTE_23 = Version(pd.__version__) < Version("2.3.999")
472471
NUMPY20 = np.lib.NumpyVersion(np.__version__) >= "2.0.0"
473472

@@ -673,13 +672,5 @@ def pytest_warns_bounded(
673672
return suppress(upper_exception)
674673

675674

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