Skip to content

Commit 034fc97

Browse files
Debian Science Teamrebecca-palmer
Debian Science Team
authored andcommitted
Xfail NaN <-> NaT tests on non-x86 and warn on cast
pd.Series([np.nan]).astype('datetime64[ns]')[0] = pd.NaT on x86 but 1970-01-01 on arm* because float NaN -> int is undefined: numpy/numpy#8325 pandas-dev/pandas#17792 pandas-dev/pandas#26964 On s390x it's the maximum _positive_ value (2**63-1 ns = year 2262) Author: Andreas Tille <[email protected]>, Graham Inggs <[email protected]>, Rebecca N. Palmer <[email protected]> Bug-Debian: https://bugs.debian.org/877754 Gbp-Pq: Name xfail_tests_nonintel_nannat.patch
1 parent bdd0c22 commit 034fc97

File tree

8 files changed

+37
-0
lines changed

8 files changed

+37
-0
lines changed

pandas/core/dtypes/cast.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
""" routings for casting """
22

33
from datetime import datetime, timedelta
4+
import warnings
5+
import platform
6+
import re
7+
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
48

59
import numpy as np
610

@@ -723,6 +727,8 @@ def astype_nansafe(arr, dtype, copy=True, skipna=False):
723727
"The '{dtype}' dtype has no unit. " "Please pass in '{dtype}[ns]' instead."
724728
)
725729
raise ValueError(msg.format(dtype=dtype.name))
730+
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():
731+
warnings.warn(warn_nannat_platform)
726732

727733
if copy or is_object_dtype(arr) or is_object_dtype(dtype):
728734
# 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"):
10401046
value = iNaT
10411047
else:
10421048
value = np.array(value, copy=False)
1049+
if warn_nannat_platform and np.issubdtype(value.dtype, np.floating) and not np.isfinite(value).all():
1050+
warnings.warn(warn_nannat_platform)
10431051

10441052
# have a scalar array-like (e.g. NaT)
10451053
if value.ndim == 0:

pandas/tests/dtypes/cast/test_downcast.py

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
from pandas import DatetimeIndex, Series, Timestamp
77
from pandas.util import testing as tm
8+
import platform
9+
import re
10+
is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
811

912

1013
@pytest.mark.parametrize(
@@ -68,6 +71,7 @@ def test_downcast_conversion_empty(any_real_dtype):
6871
tm.assert_numpy_array_equal(result, np.array([], dtype=np.int64))
6972

7073

74+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
7175
@pytest.mark.parametrize("klass", [np.datetime64, np.timedelta64])
7276
def test_datetime_likes_nan(klass):
7377
dtype = klass.__name__ + "[ns]"

pandas/tests/frame/test_analytics.py

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
import numpy as np
77
import pytest
8+
import platform
9+
import re
10+
is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
811

912
import pandas.util._test_decorators as td
1013

@@ -1368,6 +1371,7 @@ def test_sum_prod_nanops(self, method, unit):
13681371
expected = pd.Series(result, index=["A", "B"])
13691372
tm.assert_series_equal(result, expected)
13701373

1374+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
13711375
def test_sum_nanops_timedelta(self):
13721376
# prod isn't defined on timedeltas
13731377
idx = ["a", "b", "c"]

pandas/tests/frame/test_indexing.py

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import pandas.core.common as com
2727
from pandas.core.indexing import IndexingError
2828
from pandas.tests.frame.common import TestData
29+
import platform
30+
import re
31+
is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
2932
import pandas.util.testing as tm
3033
from pandas.util.testing import (
3134
assert_almost_equal,
@@ -3049,6 +3052,7 @@ def test_where_bug_transposition(self):
30493052
result = a.where(do_not_replace, b)
30503053
assert_frame_equal(result, expected)
30513054

3055+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)#not found
30523056
def test_where_datetime(self):
30533057

30543058
# GH 3311

pandas/tests/indexes/datetimes/test_datetime.py

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import dateutil
44
import numpy as np
55
import pytest
6+
import platform
7+
import re
8+
is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
69

710
import pandas as pd
811
from pandas import DataFrame, DatetimeIndex, Index, Timestamp, date_range, offsets
@@ -64,6 +67,7 @@ def test_time_overflow_for_32bit_machines(self):
6467
idx2 = pd.date_range(end="2000", periods=periods, freq="S")
6568
assert len(idx2) == periods
6669

70+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
6771
def test_nat(self):
6872
assert DatetimeIndex([np.nan])[0] is pd.NaT
6973

pandas/tests/reductions/test_reductions.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import numpy as np
44
import pytest
5+
import platform
6+
import re
7+
is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
58

69
import pandas as pd
710
from pandas import (
@@ -1145,6 +1148,7 @@ def test_mode_mixeddtype(self, dropna, expected1, expected2):
11451148
expected = Series(expected2, dtype=object)
11461149
tm.assert_series_equal(result, expected)
11471150

1151+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
11481152
@pytest.mark.parametrize(
11491153
"dropna, expected1, expected2",
11501154
[

pandas/tests/series/test_constructors.py

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
from pandas.core.dtypes.common import is_categorical_dtype, is_datetime64tz_dtype
1414
from pandas.core.dtypes.dtypes import CategoricalDtype, ordered_sentinel
15+
import platform
16+
import re
17+
is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
1518

1619
import pandas as pd
1720
from pandas import (
@@ -963,6 +966,7 @@ def test_construction_to_datetimelike_unit(self, arr_dtype, dtype, unit):
963966

964967
tm.assert_series_equal(result, expected)
965968

969+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
966970
@pytest.mark.parametrize("arg", ["2013-01-01 00:00:00", pd.NaT, np.nan, None])
967971
def test_constructor_with_naive_string_and_datetimetz_dtype(self, arg):
968972
# GH 17415: With naive string
@@ -1246,6 +1250,7 @@ def test_NaT_scalar(self):
12461250
series[2] = val
12471251
assert isna(series[2])
12481252

1253+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
12491254
def test_NaT_cast(self):
12501255
# GH10747
12511256
result = Series([np.nan]).astype("M8[ns]")

pandas/tests/test_algos.py

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
from pandas.core.sorting import safe_sort
3131
import pandas.util.testing as tm
3232
from pandas.util.testing import assert_almost_equal
33+
import platform
34+
import re
35+
is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
3336

3437

3538
class TestMatch:
@@ -1035,6 +1038,7 @@ def test_dropna(self):
10351038
expected = Series([2, 1, 1], index=[5.0, 10.3, np.nan])
10361039
tm.assert_series_equal(result, expected)
10371040

1041+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
10381042
def test_value_counts_normalized(self):
10391043
# GH12558
10401044
s = Series([1, 2, np.nan, np.nan, np.nan])

0 commit comments

Comments
 (0)