Skip to content

Commit

Permalink
replace windows/mac m1 checks with float128 check
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicBboy committed Sep 18, 2021
1 parent 0b71f9e commit 29392c4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
19 changes: 9 additions & 10 deletions pandera/engines/numpy_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .. import dtypes, errors
from ..dtypes import immutable
from ..system import MAC_M1_PLATFORM, WINDOWS_PLATFORM
from ..system import FLOAT_128_AVAILABLE
from . import engine, utils
from .type_aliases import PandasObject

Expand Down Expand Up @@ -224,17 +224,16 @@ class UInt8(UInt16):
_float_equivalents = _build_number_equivalents(
builtin_name="float",
pandera_name="Float",
sizes=(
[64, 32, 16]
if WINDOWS_PLATFORM or MAC_M1_PLATFORM
else [128, 64, 32, 16]
),
sizes=[128, 64, 32, 16] if FLOAT_128_AVAILABLE else [64, 32, 16],
)


if not WINDOWS_PLATFORM or MAC_M1_PLATFORM:
# not supported in windows
if FLOAT_128_AVAILABLE:
# not supported in windows:
# https://github.com/winpython/winpython/issues/613
#
# or Mac M1:
# https://github.com/pandera-dev/pandera/issues/623
@Engine.register_dtype(equivalents=_float_equivalents[128])
@immutable
class Float128(DataType, dtypes.Float128):
Expand Down Expand Up @@ -278,11 +277,11 @@ class Float16(Float32):
_complex_equivalents = _build_number_equivalents(
builtin_name="complex",
pandera_name="Complex",
sizes=[128, 64] if WINDOWS_PLATFORM or MAC_M1_PLATFORM else [256, 128, 64],
sizes=[256, 128, 64] if FLOAT_128_AVAILABLE else [128, 64],
)


if not WINDOWS_PLATFORM or MAC_M1_PLATFORM:
if FLOAT_128_AVAILABLE:
# not supported in windows
# https://github.com/winpython/winpython/issues/613
@Engine.register_dtype(equivalents=_complex_equivalents[256])
Expand Down
8 changes: 3 additions & 5 deletions pandera/engines/pandas_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from .. import dtypes, errors
from ..dtypes import immutable
from ..system import MAC_M1_PLATFORM, WINDOWS_PLATFORM
from ..system import FLOAT_128_AVAILABLE
from . import engine, numpy_engine, utils
from .type_aliases import PandasDataType, PandasExtensionType, PandasObject

Expand Down Expand Up @@ -340,9 +340,7 @@ class UINT8(UINT16):
_register_numpy_numbers(
builtin_name="float",
pandera_name="Float",
sizes=[64, 32, 16]
if WINDOWS_PLATFORM or MAC_M1_PLATFORM
else [128, 64, 32, 16],
sizes=[128, 64, 32, 16] if FLOAT_128_AVAILABLE else [64, 32, 16],
)

# ###############################################################################
Expand All @@ -352,7 +350,7 @@ class UINT8(UINT16):
_register_numpy_numbers(
builtin_name="complex",
pandera_name="Complex",
sizes=[128, 64] if WINDOWS_PLATFORM or MAC_M1_PLATFORM else [256, 128, 64],
sizes=[256, 128, 64] if FLOAT_128_AVAILABLE else [128, 64],
)

# ###############################################################################
Expand Down
11 changes: 5 additions & 6 deletions pandera/system.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""System/OS global variables."""
"""Global variables relating to OS."""

import platform
import numpy as np

WINDOWS_PLATFORM = platform.system() == "Windows"
MAC_M1_PLATFORM = (
platform.platform() == "Darwin" and platform.machine().startswith("arm")
)
# Windows and Mac M1 don't support floats of this precision:
# https://github.com/pandera-dev/pandera/issues/623
FLOAT_128_AVAILABLE = hasattr(np, "float128")
4 changes: 2 additions & 2 deletions tests/core/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

import pandera as pa
from pandera.system import MAC_M1_PLATFORM, WINDOWS_PLATFORM
from pandera.system import FLOAT_128_AVAILABLE


@pytest.mark.parametrize(
Expand Down Expand Up @@ -43,7 +43,7 @@ def test_deprecate_pandas_dtype(schema_cls, as_pos_arg):
def test_deprecate_pandas_dtype_enum(schema_cls):
"""Test that using the PandasDtype enum raises a DeprecationWarning."""
for attr in pa.PandasDtype:
if (WINDOWS_PLATFORM or MAC_M1_PLATFORM) and attr in {
if not FLOAT_128_AVAILABLE and attr in {
"Float128",
"Complex256",
}:
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import pandera as pa
from pandera.engines import pandas_engine
from pandera.system import MAC_M1_PLATFORM, WINDOWS_PLATFORM
from pandera.system import FLOAT_128_AVAILABLE

# List dtype classes and associated pandas alias,
# except for parameterizable dtypes that should also list examples of
Expand Down Expand Up @@ -83,7 +83,7 @@
}


if not WINDOWS_PLATFORM or MAC_M1_PLATFORM:
if FLOAT_128_AVAILABLE:
float_dtypes.update(
{
pa.Float128: "float128",
Expand Down

0 comments on commit 29392c4

Please sign in to comment.