Xfail NaN <-> NaT tests on non-x86 and warn on cast
authorDebian Science Team <debian-science-maintainers@lists.alioth.debian.org>
Mon, 7 Dec 2020 23:06:28 +0000 (23:06 +0000)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Mon, 7 Dec 2020 23:06:28 +0000 (23:06 +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
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 bdf294a380edc019e09d095c28505f10c377a309..715faf359e798c40cf1b164d0013ea178816ff34 100644 (file)
@@ -4,6 +4,10 @@ Routines for casting.
 
 from datetime import date, datetime, timedelta
 from typing import TYPE_CHECKING, Any, List, Optional, Tuple, Type
+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
 
@@ -991,6 +995,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.
@@ -1367,6 +1373,8 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
                     value = iNaT
             elif not is_sparse(value):
                 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 d114a3178b686744f4daf1ff05fa4329bee255e3..2aee2b62418be4701679e11674002afd352071fd 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]))
 
 
 @pytest.fixture(params=["default", "float_string", "mixed_float", "mixed_int"])
@@ -352,6 +355,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 52a1e3aae905856c255d18eae8c0cc15a307c0c7..6c834f421faf0bbb27d6a607143f61bdc360322c 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(
@@ -802,6 +805,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 e6758df2d3d93db7f2de8bd0f9339c95520066d5..47b1b90b570db070a80fb1bcd24c16a784d4bfec 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
 
@@ -95,6 +98,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 a112bc80b60b0aa99a2083c6779c59dc79439f9d..451fb2c0441b9832473f898e7c1c082e61d86994 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():
@@ -1199,6 +1202,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 f811806a897ee61ba785ae199cf546119d59db6e..1453123f09345cc45790bc5a3e0d5217a6964165 100644 (file)
@@ -27,7 +27,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(
@@ -959,6 +961,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
@@ -1289,6 +1292,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 a78f8ad3cd4dd38834c07e8f79ce26ab8f614cd8..2102cbd45dba3feb3e7c3825647226089c296fc1 100644 (file)
@@ -34,6 +34,9 @@ import pandas._testing as tm
 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:
@@ -1144,6 +1147,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])