From 29392c4a8eff48cc1c7cda0d8ec8dc9cc0e5506b Mon Sep 17 00:00:00 2001 From: cosmicBboy Date: Fri, 17 Sep 2021 01:08:48 -0400 Subject: [PATCH] replace windows/mac m1 checks with float128 check --- pandera/engines/numpy_engine.py | 19 +++++++++---------- pandera/engines/pandas_engine.py | 8 +++----- pandera/system.py | 11 +++++------ tests/core/test_deprecations.py | 4 ++-- tests/core/test_dtypes.py | 4 ++-- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/pandera/engines/numpy_engine.py b/pandera/engines/numpy_engine.py index 07f4d5017..c66bb5fc4 100644 --- a/pandera/engines/numpy_engine.py +++ b/pandera/engines/numpy_engine.py @@ -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 @@ -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): @@ -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]) diff --git a/pandera/engines/pandas_engine.py b/pandera/engines/pandas_engine.py index 61ad9b189..9b0e9ca15 100644 --- a/pandera/engines/pandas_engine.py +++ b/pandera/engines/pandas_engine.py @@ -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 @@ -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], ) # ############################################################################### @@ -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], ) # ############################################################################### diff --git a/pandera/system.py b/pandera/system.py index 6f42ec856..88e23049f 100644 --- a/pandera/system.py +++ b/pandera/system.py @@ -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") diff --git a/tests/core/test_deprecations.py b/tests/core/test_deprecations.py index 5586f5dfc..813e6cbe1 100644 --- a/tests/core/test_deprecations.py +++ b/tests/core/test_deprecations.py @@ -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( @@ -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", }: diff --git a/tests/core/test_dtypes.py b/tests/core/test_dtypes.py index 3a4e1874f..dcb013b6b 100644 --- a/tests/core/test_dtypes.py +++ b/tests/core/test_dtypes.py @@ -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 @@ -83,7 +83,7 @@ } -if not WINDOWS_PLATFORM or MAC_M1_PLATFORM: +if FLOAT_128_AVAILABLE: float_dtypes.update( { pa.Float128: "float128",