Xfail NaN <-> NaT tests on non-x86 and warn on cast
authorDebian Science Team <debian-science-maintainers@lists.alioth.debian.org>
Wed, 26 Feb 2020 18:45:58 +0000 (18:45 +0000)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Wed, 26 Feb 2020 18:45:58 +0000 (18:45 +0000)
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

Gbp-Pq: Name xfail_tests_nonintel_nannat.patch

pandas/core/dtypes/cast.py
pandas/tests/dtypes/cast/test_downcast.py
pandas/tests/frame/test_analytics.py
pandas/tests/frame/test_indexing.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 44a3fefb1689a395f9116710feb7bb2f2b4d885f..94bd0562fdd8621c888bbc5e8ef7adbb21c5dea5 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
 
@@ -723,6 +727,8 @@ def astype_nansafe(arr, dtype, copy=True, skipna=False):
             "The '{dtype}' dtype has no unit. " "Please pass in '{dtype}[ns]' instead."
         )
         raise ValueError(msg.format(dtype=dtype.name))
+    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.
@@ -1040,6 +1046,8 @@ def maybe_cast_to_datetime(value, dtype, errors="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 d574b03a8c7249c57c6d464cc9a709fc44237431..a95fd42178be9bf35fda8a020c2ba9b702a9f914 100644 (file)
@@ -5,6 +5,9 @@ from pandas.core.dtypes.cast import maybe_downcast_to_dtype
 
 from pandas import DatetimeIndex, Series, Timestamp
 from pandas.util import testing as tm
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
 
 
 @pytest.mark.parametrize(
@@ -68,6 +71,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 e99208ac78e15f8dcf9beafcfcbd4968eb77d6ff..5623a48b3648877681ee5a94b84bd25e3890b2d2 100644 (file)
@@ -5,6 +5,9 @@ import warnings
 
 import numpy as np
 import pytest
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
 
 import pandas.util._test_decorators as td
 
@@ -1368,6 +1371,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 7b1e7c58f2c0692e7ec67c71e6e44a9fe14662a3..0dc6903780c1fef1a03e975fbf0e01289925fe5c 100644 (file)
@@ -26,6 +26,9 @@ from pandas import (
 import pandas.core.common as com
 from pandas.core.indexing import IndexingError
 from pandas.tests.frame.common import TestData
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
 import pandas.util.testing as tm
 from pandas.util.testing import (
     assert_almost_equal,
@@ -3049,6 +3052,7 @@ class TestDataFrameIndexing(TestData):
         result = a.where(do_not_replace, b)
         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 bb3fe7a136204fd51c20589e65bcc6e8540a820d..da2ddf21d965bb4ff01d12470c5bcf893f4222ff 100644 (file)
@@ -3,6 +3,9 @@ from datetime import date
 import dateutil
 import numpy as np
 import pytest
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
 
 import pandas as pd
 from pandas import DataFrame, DatetimeIndex, Index, Timestamp, date_range, offsets
@@ -64,6 +67,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 05ebff4387908196fd106bbd6b823c577b79fba2..181a72d72ead89fc1228dd2718c16a7723b70d06 100644 (file)
@@ -2,6 +2,9 @@ from datetime import datetime, timedelta
 
 import numpy as np
 import pytest
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
 
 import pandas as pd
 from pandas import (
@@ -1145,6 +1148,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 2f09d777e719cb461dd76a20cca8a9231aff51ea..a47432999cf14e2553cb9c7ce8072e87d7f51eca 100644 (file)
@@ -12,6 +12,9 @@ from pandas.compat import PY36
 
 from pandas.core.dtypes.common import is_categorical_dtype, is_datetime64tz_dtype
 from pandas.core.dtypes.dtypes import CategoricalDtype, ordered_sentinel
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
 
 import pandas as pd
 from pandas import (
@@ -963,6 +966,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
@@ -1246,6 +1250,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 c0d73821020b5326f55eec74953ead1f8ee2c2c0..32b2834d8acd8278b6751f4d38194d537537c200 100644 (file)
@@ -30,6 +30,9 @@ import pandas.core.common as com
 from pandas.core.sorting import safe_sort
 import pandas.util.testing as tm
 from pandas.util.testing import assert_almost_equal
+import platform
+import re
+is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
 
 
 class TestMatch:
@@ -1035,6 +1038,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])