Skip to content

Commit 2b18f72

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 89b7a56 commit 2b18f72

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
@@ -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

@@ -891,6 +895,8 @@ def astype_nansafe(arr, dtype, copy: bool = True, skipna: bool = False):
891895
f"'{dtype.name}[ns]' instead."
892896
)
893897
raise ValueError(msg)
898+
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():
899+
warnings.warn(warn_nannat_platform)
894900

895901
if copy or is_object_dtype(arr) or is_object_dtype(dtype):
896902
# Explicit copy, or required since NumPy can't view from / to object.
@@ -1263,6 +1269,8 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
12631269
value = iNaT
12641270
else:
12651271
value = np.array(value, copy=False)
1272+
if warn_nannat_platform and np.issubdtype(value.dtype, np.floating) and not np.isfinite(value).all():
1273+
warnings.warn(warn_nannat_platform)
12661274

12671275
# have a scalar array-like (e.g. NaT)
12681276
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
class TestDataFrameIndexingWhere:
@@ -340,6 +343,7 @@ def test_where_bug_transposition(self):
340343
result = a.where(do_not_replace, b)
341344
tm.assert_frame_equal(result, expected)
342345

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

345349
# 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(
@@ -790,6 +793,7 @@ def test_sum_prod_nanops(self, method, unit):
790793
expected = pd.Series(result, index=["A", "B"])
791794
tm.assert_series_equal(result, expected)
792795

796+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
793797
def test_sum_nanops_timedelta(self):
794798
# prod isn't defined on timedeltas
795799
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

@@ -63,6 +66,7 @@ def test_time_overflow_for_32bit_machines(self):
6366
idx2 = pd.date_range(end="2000", periods=periods, freq="S")
6467
assert len(idx2) == periods
6568

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

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():
@@ -1142,6 +1145,7 @@ def test_mode_mixeddtype(self, dropna, expected1, expected2):
11421145
expected = Series(expected2, dtype=object)
11431146
tm.assert_series_equal(result, expected)
11441147

1148+
@pytest.mark.xfail(condition=not is_nannat_working,reason="https://bugs.debian.org/877754",strict=False)
11451149
@pytest.mark.parametrize(
11461150
"dropna, expected1, expected2",
11471151
[

pandas/tests/series/test_constructors.py

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

3335
class TestSeriesConstructors:
3436
@pytest.mark.parametrize(
@@ -960,6 +962,7 @@ def test_construction_to_datetimelike_unit(self, arr_dtype, dtype, unit):
960962

961963
tm.assert_series_equal(result, expected)
962964

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

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

pandas/tests/test_algos.py

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

3942

4043
class TestFactorize:
@@ -1046,6 +1049,7 @@ def test_dropna(self):
10461049
expected = Series([2, 1, 1], index=[5.0, 10.3, np.nan])
10471050
tm.assert_series_equal(result, expected)
10481051

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

0 commit comments

Comments
 (0)