Xfail NaN <-> NaT tests on non-x86 and warn on cast
authorDebian Science Team <debian-science-maintainers@lists.alioth.debian.org>
Wed, 26 Aug 2020 21:34:50 +0000 (22:34 +0100)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Wed, 26 Aug 2020 21:34:50 +0000 (22:34 +0100)
pd.Series([np.nan]).astype('datetime64[ns]')[0] = pd.NaT on x86
but 1970-01-01 on arm* because float NaN -> int is undefined:
https://github.com/numpy/numpy/issues/8325
https://github.com/pandas-dev/pandas/issues/17792
https://github.com/pandas-dev/pandas/issues/26964

On s390x it's the maximum _positive_ value (2**63-1 ns = year 2262)

Author: Andreas Tille <tille@debian.org>, Graham Inggs <ginggs@debian.org>, Rebecca N. Palmer <rebecca_palmer@zoho.com>
Bug-Debian: https://bugs.debian.org/877754
Forwarded: no

Gbp-Pq: Name xfail_tests_nonintel_nannat.patch

pandas/core/dtypes/cast.py
pandas/tests/dtypes/cast/test_downcast.py
pandas/tests/frame/indexing/test_where.py
pandas/tests/frame/test_analytics.py
pandas/tests/indexes/datetimes/test_datetime.py
pandas/tests/reductions/test_reductions.py
pandas/tests/series/test_constructors.py
pandas/tests/test_algos.py

index d4b60ec186b86ef5f4860ea90baf36d407e10305..1e13b6038f122efb4664fa618c46376bec068707 100644 (file)
@@ -1,6 +1,10 @@
 """ routings for casting """
 
 from datetime import datetime, timedelta
+import warnings
+import platform
+import re
+warn_nannat_platform = "Non-x86 system detected, float -> datetime/timedelta may not handle NaNs correctly - https://bugs.debian.org/877754" if not bool(re.match('i.?86|x86',platform.uname()[4])) else False
 
 import numpy as np
 
@@ -891,6 +895,8 @@ def astype_nansafe(arr, dtype, copy: bool = True, skipna: bool = False):
             f"'{dtype.name}[ns]' instead."
         )
         raise ValueError(msg)
+    if warn_nannat_platform and (is_datetime64_dtype(dtype) or is_timedelta64_dtype(dtype)) and np.issubdtype(arr.dtype, np.floating) and not np.isfinite(arr).all():
+        warnings.warn(warn_nannat_platform)
 
     if copy or is_object_dtype(arr) or is_object_dtype(dtype):
         # Explicit copy, or required since NumPy can't view from / to object.
@@ -1263,6 +1269,8 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
                     value = iNaT
             else:
                 value = np.array(value, copy=False)
+                if warn_nannat_platform and np.issubdtype(value.dtype, np.floating) and not np.isfinite(value).all():
+                    warnings.warn(warn_nannat_platform)
 
                 # have a scalar array-like (e.g. NaT)
                 if value.ndim == 0:
index d6e6ed3022b75c862b64bb9a5f625cd8a4ab0a8c..0bfe74af832bbf4a3cb6e833afcffa9dec7dda4f 100644 (file)
@@ -7,6 +7,9 @@ from pandas.core.dtypes.cast import maybe_downcast_to_dtype
 
 from pandas import DatetimeIndex, Series, Timestamp
 import pandas._testing as tm
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
 
 
 @pytest.mark.parametrize(
@@ -77,6 +80,7 @@ def test_downcast_conversion_empty(any_real_dtype):
     tm.assert_numpy_array_equal(result, np.array([], dtype=np.int64))
 
 
+@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
 @pytest.mark.parametrize("klass", [np.datetime64, np.timedelta64])
 def test_datetime_likes_nan(klass):
     dtype = klass.__name__ + "[ns]"
index df1b128dcd2275db719e103bb4169edc74e75c1e..76fc7beea017337779e1b2c40d83d7bcbf9aed0b 100644 (file)
@@ -8,6 +8,9 @@ from pandas.core.dtypes.common import is_scalar
 import pandas as pd
 from pandas import DataFrame, DatetimeIndex, Series, Timestamp, date_range, isna
 import pandas._testing as tm
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
 
 
 class TestDataFrameIndexingWhere:
@@ -340,6 +343,7 @@ class TestDataFrameIndexingWhere:
         result = a.where(do_not_replace, b)
         tm.assert_frame_equal(result, expected)
 
+    @pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)#not found
     def test_where_datetime(self):
 
         # GH 3311
index 8e1c3effb6cfc65f9adfcbc74924b7f4654782b8..981f98c6bd76ef105a486499d63339028fa5d35a 100644 (file)
@@ -23,6 +23,9 @@ from pandas import (
 import pandas._testing as tm
 import pandas.core.algorithms as algorithms
 import pandas.core.nanops as nanops
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
 
 
 def assert_stat_op_calc(
@@ -790,6 +793,7 @@ class TestDataFrameAnalytics:
         expected = pd.Series(result, index=["A", "B"])
         tm.assert_series_equal(result, expected)
 
+    @pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
     def test_sum_nanops_timedelta(self):
         # prod isn't defined on timedeltas
         idx = ["a", "b", "c"]
index ca18d6fbea11a4c23f3f98b6e0c8c9cbdb4a7ce7..dbdf3ed9378c1b5ef45fb2cde533f4a6276c6015 100644 (file)
@@ -7,6 +7,9 @@ import pytest
 import pandas as pd
 from pandas import DataFrame, DatetimeIndex, Index, Timestamp, date_range, offsets
 import pandas._testing as tm
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
 
 randn = np.random.randn
 
@@ -63,6 +66,7 @@ class TestDatetimeIndex:
         idx2 = pd.date_range(end="2000", periods=periods, freq="S")
         assert len(idx2) == periods
 
+    @pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
     def test_nat(self):
         assert DatetimeIndex([np.nan])[0] is pd.NaT
 
index 7400b049961d5ca314337e6ce148556fded4cd7b..b1e80cab0bf8f67f5fceebfb091956ef3edc2a2c 100644 (file)
@@ -23,6 +23,9 @@ from pandas import (
 )
 import pandas._testing as tm
 from pandas.core import nanops
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
 
 
 def get_objs():
@@ -1142,6 +1145,7 @@ class TestSeriesMode:
         expected = Series(expected2, dtype=object)
         tm.assert_series_equal(result, expected)
 
+    @pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
     @pytest.mark.parametrize(
         "dropna, expected1, expected2",
         [
index c38e5708be09b463c10a0604416e7414436d3bca..dc0bbbce0c484f8c62a4b87fcb6701008a348209 100644 (file)
@@ -28,7 +28,9 @@ from pandas import (
 )
 import pandas._testing as tm
 from pandas.core.arrays import IntervalArray, period_array
-
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
 
 class TestSeriesConstructors:
     @pytest.mark.parametrize(
@@ -960,6 +962,7 @@ class TestSeriesConstructors:
 
         tm.assert_series_equal(result, expected)
 
+    @pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
     @pytest.mark.parametrize("arg", ["2013-01-01 00:00:00", pd.NaT, np.nan, None])
     def test_constructor_with_naive_string_and_datetimetz_dtype(self, arg):
         # GH 17415: With naive string
@@ -1272,6 +1275,7 @@ class TestSeriesConstructors:
         series[2] = val
         assert isna(series[2])
 
+    @pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
     def test_NaT_cast(self):
         # GH10747
         result = Series([np.nan]).astype("M8[ns]")
index 57ee3bedd4d9fc4387a68a131e047ee72c25a0f2..126f00cd78a404d8c13725342367cbcd6292c747 100644 (file)
@@ -35,6 +35,9 @@ from pandas.conftest import BYTES_DTYPES, STRING_DTYPES
 import pandas.core.algorithms as algos
 from pandas.core.arrays import DatetimeArray
 import pandas.core.common as com
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
 
 
 class TestFactorize:
@@ -1046,6 +1049,7 @@ class TestValueCounts:
             expected = Series([2, 1, 1], index=[5.0, 10.3, np.nan])
             tm.assert_series_equal(result, expected)
 
+    @pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
     def test_value_counts_normalized(self):
         # GH12558
         s = Series([1, 2, np.nan, np.nan, np.nan])