Skip to content

Commit 061cb41

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) On riscv64 one test case raises an exception (though I suspect not the general case since there aren't more). 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 28f5b96 commit 061cb41

File tree

9 files changed

+40
-0
lines changed

9 files changed

+40
-0
lines changed

pandas/core/dtypes/cast.py

+7
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
TimedeltaArray,
101101
)
102102

103+
import platform
104+
import re
105+
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
103106
_int8_max = np.iinfo(np.int8).max
104107
_int16_max = np.iinfo(np.int16).max
105108
_int32_max = np.iinfo(np.int32).max
@@ -1195,6 +1198,8 @@ def astype_nansafe(
11951198
f"'{dtype.name}[ns]' instead."
11961199
)
11971200
raise ValueError(msg)
1201+
if warn_nannat_platform and (is_datetime64_dtype(dtype) or is_timedelta64_dtype(dtype)) and not (is_datetime64_dtype(arr.dtype) or is_timedelta64_dtype(arr.dtype)) and np.issubdtype(arr.dtype, np.floating) and not np.isfinite(arr).all():
1202+
warnings.warn(warn_nannat_platform)
11981203

11991204
if copy or is_object_dtype(arr.dtype) or is_object_dtype(dtype):
12001205
# Explicit copy, or required since NumPy can't view from / to object.
@@ -1625,6 +1630,8 @@ def maybe_cast_to_datetime(
16251630
dtype = ensure_nanosecond_dtype(dtype)
16261631

16271632
value = np.array(value, copy=False)
1633+
if warn_nannat_platform and not (is_datetime64_dtype(value.dtype) or is_timedelta64_dtype(value.dtype)) and np.issubdtype(value.dtype, np.floating) and not np.isfinite(value).all():
1634+
warnings.warn(warn_nannat_platform)
16281635

16291636
# we have an array of datetime or timedeltas & nulls
16301637
if value.size or not is_dtype_equal(value.dtype, dtype):

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 Series
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
@@ -16,6 +16,9 @@
1616
isna,
1717
)
1818
import pandas._testing as tm
19+
import platform
20+
import re
21+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
1922

2023

2124
@pytest.fixture(params=["default", "float_string", "mixed_float", "mixed_int"])
@@ -360,6 +363,7 @@ def test_where_bug_transposition(self):
360363
result = a.where(do_not_replace, b)
361364
tm.assert_frame_equal(result, expected)
362365

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

365369
# GH 3311

pandas/tests/frame/test_reductions.py

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import pandas._testing as tm
2929
import pandas.core.algorithms as algorithms
3030
import pandas.core.nanops as nanops
31+
import platform
32+
import re
33+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
3134

3235

3336
def assert_stat_op_calc(
@@ -845,6 +848,7 @@ def test_sum_prod_nanops(self, method, unit, numeric_only):
845848
expected = Series(result, index=["A", "B"])
846849
tm.assert_series_equal(result, expected)
847850

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

pandas/tests/indexes/datetimes/test_datetime.py

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
offsets,
1515
)
1616
import pandas._testing as tm
17+
import platform
18+
import re
19+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
1720

1821

1922
class TestDatetimeIndex:
@@ -55,6 +58,7 @@ def test_time_overflow_for_32bit_machines(self):
5558
idx2 = date_range(end="2000", periods=periods, freq="S")
5659
assert len(idx2) == periods
5760

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

pandas/tests/reductions/test_reductions.py

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

3134

3235
def get_objs():
@@ -1346,6 +1349,7 @@ def test_mode_mixeddtype(self, dropna, expected1, expected2):
13461349
expected = Series(expected2, dtype=object)
13471350
tm.assert_series_equal(result, expected)
13481351

1352+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
13491353
@pytest.mark.parametrize(
13501354
"dropna, expected1, expected2",
13511355
[

pandas/tests/series/test_constructors.py

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
)
4848
from pandas.core.internals.blocks import NumericBlock
4949

50+
import platform
51+
import re
52+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
5053

5154
class TestSeriesConstructors:
5255
@pytest.mark.parametrize(
@@ -1057,6 +1060,7 @@ def test_construction_to_datetimelike_unit(self, arr_dtype, dtype, unit):
10571060

10581061
tm.assert_series_equal(result, expected)
10591062

1063+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
10601064
@pytest.mark.parametrize("arg", ["2013-01-01 00:00:00", NaT, np.nan, None])
10611065
def test_constructor_with_naive_string_and_datetimetz_dtype(self, arg):
10621066
# GH 17415: With naive string
@@ -1434,6 +1438,7 @@ def test_NaT_scalar(self):
14341438
series[2] = val
14351439
assert isna(series[2])
14361440

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

pandas/tests/test_algos.py

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
import pandas.core.algorithms as algos
4646
from pandas.core.arrays import DatetimeArray
4747
import pandas.core.common as com
48+
import platform
49+
import re
50+
is_nannat_working=bool(re.match('i.?86|x86|s390|ppc',platform.uname()[4]))
4851

4952

5053
class TestFactorize:
@@ -1265,6 +1268,7 @@ def test_dropna(self):
12651268
expected = Series([3, 2, 1], index=[5.0, 10.3, np.nan])
12661269
tm.assert_series_equal(result, expected)
12671270

1271+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
12681272
def test_value_counts_normalized(self):
12691273
# GH12558
12701274
s = Series([1] * 2 + [2] * 3 + [np.nan] * 5)

pandas/tests/tools/test_to_datetime.py

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
OutOfBoundsTimedelta,
2626
)
2727
import pandas.util._test_decorators as td
28+
import platform
29+
import re
30+
is_platform_x86 = bool(re.match('i.?86|x86',platform.uname()[4]))
2831

2932
from pandas.core.dtypes.common import is_datetime64_ns_dtype
3033

@@ -1484,6 +1487,7 @@ def test_to_datetime_errors_ignore_utc_true(self):
14841487
tm.assert_index_equal(result, expected)
14851488

14861489
# TODO: this is moved from tests.series.test_timeseries, may be redundant
1490+
@pytest.mark.xfail(not is_platform_x86, strict=False, raises=OutOfBoundsDatetime, reason="fails on riscv64")
14871491
def test_to_datetime_unit(self):
14881492

14891493
epoch = 1370745748

0 commit comments

Comments
 (0)