Skip to content

Commit 88e2278

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 Forwarded: no Gbp-Pq: Name xfail_tests_nonintel_nannat.patch
1 parent 37ff848 commit 88e2278

File tree

8 files changed

+37
-1
lines changed

8 files changed

+37
-1
lines changed

pandas/core/dtypes/cast.py

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
from datetime import date, datetime, timedelta
66
from typing import TYPE_CHECKING, Any, List, Optional, Tuple, Type
7+
import warnings
8+
import platform
9+
import re
10+
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
711

812
import numpy as np
913

@@ -989,6 +993,8 @@ def astype_nansafe(arr, dtype, copy: bool = True, skipna: bool = False):
989993
f"'{dtype.name}[ns]' instead."
990994
)
991995
raise ValueError(msg)
996+
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():
997+
warnings.warn(warn_nannat_platform)
992998

993999
if copy or is_object_dtype(arr) or is_object_dtype(dtype):
9941000
# Explicit copy, or required since NumPy can't view from / to object.
@@ -1365,6 +1371,8 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
13651371
value = iNaT
13661372
elif not is_sparse(value):
13671373
value = np.array(value, copy=False)
1374+
if warn_nannat_platform and np.issubdtype(value.dtype, np.floating) and not np.isfinite(value).all():
1375+
warnings.warn(warn_nannat_platform)
13681376

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

pandas/tests/dtypes/cast/test_downcast.py

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
from pandas import DatetimeIndex, Series, Timestamp
99
import pandas._testing as tm
10+
import platform
11+
import re
12+
is_nannat_working=bool(re.match('i.?86|x86',platform.uname()[4]))
1013

1114

1215
@pytest.mark.parametrize(
@@ -77,6 +80,7 @@ def test_downcast_conversion_empty(any_real_dtype):
7780
tm.assert_numpy_array_equal(result, np.array([], dtype=np.int64))
7881

7982

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

pandas/tests/frame/indexing/test_where.py

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import pandas as pd
99
from pandas import DataFrame, DatetimeIndex, Series, Timestamp, date_range, isna
1010
import pandas._testing as tm
11+
import platform
12+
import re
13+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
1114

1215

1316
@pytest.fixture(params=["default", "float_string", "mixed_float", "mixed_int"])
@@ -352,6 +355,7 @@ def test_where_bug_transposition(self):
352355
result = a.where(do_not_replace, b)
353356
tm.assert_frame_equal(result, expected)
354357

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

357361
# GH 3311

pandas/tests/frame/test_analytics.py

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import pandas._testing as tm
2424
import pandas.core.algorithms as algorithms
2525
import pandas.core.nanops as nanops
26+
import platform
27+
import re
28+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
2629

2730

2831
def assert_stat_op_calc(
@@ -802,6 +805,7 @@ def test_sum_prod_nanops(self, method, unit):
802805
expected = pd.Series(result, index=["A", "B"])
803806
tm.assert_series_equal(result, expected)
804807

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

pandas/tests/indexes/datetimes/test_datetime.py

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import pandas as pd
88
from pandas import DataFrame, DatetimeIndex, Index, Timestamp, date_range, offsets
99
import pandas._testing as tm
10+
import platform
11+
import re
12+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
1013

1114
randn = np.random.randn
1215

@@ -95,6 +98,7 @@ def test_time_overflow_for_32bit_machines(self):
9598
idx2 = pd.date_range(end="2000", periods=periods, freq="S")
9699
assert len(idx2) == periods
97100

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

pandas/tests/reductions/test_reductions.py

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
)
2424
import pandas._testing as tm
2525
from pandas.core import nanops
26+
import platform
27+
import re
28+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
2629

2730

2831
def get_objs():
@@ -1199,6 +1202,7 @@ def test_mode_mixeddtype(self, dropna, expected1, expected2):
11991202
expected = Series(expected2, dtype=object)
12001203
tm.assert_series_equal(result, expected)
12011204

1205+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
12021206
@pytest.mark.parametrize(
12031207
"dropna, expected1, expected2",
12041208
[

pandas/tests/series/test_constructors.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
)
2828
import pandas._testing as tm
2929
from pandas.core.arrays import IntervalArray, period_array
30-
30+
import platform
31+
import re
32+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
3133

3234
class TestSeriesConstructors:
3335
@pytest.mark.parametrize(
@@ -959,6 +961,7 @@ def test_construction_to_datetimelike_unit(self, arr_dtype, dtype, unit):
959961

960962
tm.assert_series_equal(result, expected)
961963

964+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
962965
@pytest.mark.parametrize("arg", ["2013-01-01 00:00:00", pd.NaT, np.nan, None])
963966
def test_constructor_with_naive_string_and_datetimetz_dtype(self, arg):
964967
# GH 17415: With naive string
@@ -1289,6 +1292,7 @@ def test_NaT_scalar(self):
12891292
series[2] = val
12901293
assert isna(series[2])
12911294

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

pandas/tests/test_algos.py

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
import pandas.core.algorithms as algos
3535
from pandas.core.arrays import DatetimeArray
3636
import pandas.core.common as com
37+
import platform
38+
import re
39+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
3740

3841

3942
class TestFactorize:
@@ -1144,6 +1147,7 @@ def test_dropna(self):
11441147
expected = Series([2, 1, 1], index=[5.0, 10.3, np.nan])
11451148
tm.assert_series_equal(result, expected)
11461149

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

0 commit comments

Comments
 (0)