Skip to content

Commit ef8354e

Browse files
committed
exception on platform
1 parent 9e2175d commit ef8354e

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

tests/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,5 +672,7 @@ def pytest_warns_bounded(
672672
return suppress(upper_exception)
673673

674674

675-
def is_dtype_invalid_for_platform(dtype: type | str | ExtensionDtype) -> bool:
676-
return (WINDOWS or MAC_ARM) and dtype in {"f16", "float128"}
675+
def exception_on_platform(dtype: type | str | ExtensionDtype) -> type[Exception] | None:
676+
if (WINDOWS or MAC_ARM) and dtype in {"f16", "float128"}:
677+
return TypeError
678+
return None

tests/arrays/test_floating_array.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
PANDAS_FLOAT_ARGS,
1111
PandasFloatDtypeArg,
1212
check,
13-
is_dtype_invalid_for_platform,
13+
exception_on_platform,
1414
)
1515

1616

@@ -32,8 +32,9 @@ 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-
if is_dtype_invalid_for_platform(dtype):
36-
with pytest.raises(TypeError, match=rf"data type {dtype!r} not understood"):
35+
exc = exception_on_platform(dtype)
36+
if exc:
37+
with pytest.raises(exc, match=rf"data type {dtype!r} not understood"):
3738
assert_type(pd.array([1.0], dtype=dtype), FloatingArray)
3839
else:
3940
check(pd.array([1.0], dtype=dtype), FloatingArray, target_dtype)

tests/indexes/test_index_float.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
TYPE_FLOAT_NOT_NUMPY16_ARGS,
1111
PandasAstypeFloatDtypeArg,
1212
check,
13-
is_dtype_invalid_for_platform,
13+
exception_on_platform,
1414
)
1515

1616
if TYPE_CHECKING:
@@ -52,8 +52,9 @@ def test_constructor() -> None:
5252
def test_constructor_dtype(
5353
dtype: "FloatNotNumpy16DtypeArg", target_dtype: type
5454
) -> None:
55-
if is_dtype_invalid_for_platform(dtype):
56-
with pytest.raises(TypeError, match=rf"data type {dtype!r} not understood"):
55+
exc = exception_on_platform(dtype)
56+
if exc:
57+
with pytest.raises(exc, match=rf"data type {dtype!r} not understood"):
5758
assert_type(pd.Index([1.0], dtype=dtype), "pd.Index[float]")
5859
else:
5960
check(pd.Index([1.0], dtype=dtype), pd.Index, target_dtype)
@@ -110,8 +111,9 @@ def test_astype_float(
110111
) -> None:
111112
s = pd.Index([1, 2, 3])
112113

113-
if is_dtype_invalid_for_platform(cast_arg):
114-
with pytest.raises(TypeError, match=rf"data type {cast_arg!r} not understood"):
114+
exc = exception_on_platform(cast_arg)
115+
if exc:
116+
with pytest.raises(exc, match=rf"data type {cast_arg!r} not understood"):
115117
assert_type(s.astype(cast_arg), "pd.Index[float]")
116118
else:
117119
check(s.astype(cast_arg), pd.Index, target_type)

tests/series/test_series_float.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
FloatDtypeArg,
1212
PandasAstypeFloatDtypeArg,
1313
check,
14-
is_dtype_invalid_for_platform,
14+
exception_on_platform,
1515
)
1616

1717

@@ -46,8 +46,9 @@ 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-
if is_dtype_invalid_for_platform(dtype):
50-
with pytest.raises(TypeError, match=rf"data type {dtype!r} not understood"):
49+
exc = exception_on_platform(dtype)
50+
if exc:
51+
with pytest.raises(exc, match=rf"data type {dtype!r} not understood"):
5152
assert_type(pd.Series([1.0], dtype=dtype), "pd.Series[float]")
5253
else:
5354
check(pd.Series([1.0], dtype=dtype), pd.Series, target_dtype)
@@ -102,7 +103,7 @@ def test_astype_float(
102103
) -> None:
103104
s = pd.Series([1, 2, 3])
104105

105-
if is_dtype_invalid_for_platform(cast_arg):
106+
if exception_on_platform(cast_arg):
106107
with pytest.raises(TypeError, match=rf"data type {cast_arg!r} not understood"):
107108
assert_type(s.astype(cast_arg), "pd.Series[float]")
108109
else:

0 commit comments

Comments
 (0)