Skip to content

Commit d9dc120

Browse files
Debian Science Teamrebecca-palmer
authored andcommitted
Fix test failures on 32-bit systems
Author: Rebecca N. Palmer <[email protected]> Bug-Debian: partly https://bugs.debian.org/1026351 Forwarded: no Gbp-Pq: Name tests_dont_assume_64bit.patch
1 parent 902cbb3 commit d9dc120

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

pandas/core/arrays/_ranges.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def generate_regular_range(
5050
ndarray[np.int64]
5151
Representing the given resolution.
5252
"""
53-
istart = start._value if start is not None else None
54-
iend = end._value if end is not None else None
53+
istart = int(start._value) if start is not None else None
54+
iend = int(end._value) if end is not None else None
5555
freq.nanos # raises if non-fixed frequency
5656
td = Timedelta(freq)
57-
b: int | np.int64 | np.uint64
58-
e: int | np.int64 | np.uint64
57+
b: int
58+
e: int
5959
try:
6060
td = td.as_unit( # pyright: ignore[reportGeneralTypeIssues]
6161
unit, round_ok=False
@@ -98,7 +98,7 @@ def generate_regular_range(
9898

9999
def _generate_range_overflow_safe(
100100
endpoint: int, periods: int, stride: int, side: str = "start"
101-
) -> np.int64 | np.uint64:
101+
) -> int:
102102
"""
103103
Calculate the second endpoint for passing to np.arange, checking
104104
to avoid an integer overflow. Catch OverflowError and re-raise
@@ -117,7 +117,7 @@ def _generate_range_overflow_safe(
117117
118118
Returns
119119
-------
120-
other_end : np.int64 | np.uint64
120+
other_end : int
121121
122122
Raises
123123
------
@@ -159,13 +159,13 @@ def _generate_range_overflow_safe(
159159
remaining = periods - mid_periods
160160
assert 0 < remaining < periods, (remaining, periods, endpoint, stride)
161161

162-
midpoint = int(_generate_range_overflow_safe(endpoint, mid_periods, stride, side))
162+
midpoint = _generate_range_overflow_safe(endpoint, mid_periods, stride, side)
163163
return _generate_range_overflow_safe(midpoint, remaining, stride, side)
164164

165165

166166
def _generate_range_overflow_safe_signed(
167167
endpoint: int, periods: int, stride: int, side: str
168-
) -> np.int64 | np.uint64:
168+
) -> int:
169169
"""
170170
A special case for _generate_range_overflow_safe where `periods * stride`
171171
can be calculated without overflowing int64 bounds.
@@ -183,7 +183,7 @@ def _generate_range_overflow_safe_signed(
183183
# Putting this into a DatetimeArray/TimedeltaArray
184184
# would incorrectly be interpreted as NaT
185185
raise OverflowError
186-
return result
186+
return int(result)
187187
except (FloatingPointError, OverflowError):
188188
# with endpoint negative and addend positive we risk
189189
# FloatingPointError; with reversed signed we risk OverflowError
@@ -202,7 +202,7 @@ def _generate_range_overflow_safe_signed(
202202
i64max = np.uint64(i8max)
203203
assert uresult > i64max
204204
if uresult <= i64max + np.uint64(stride):
205-
return uresult
205+
return int(uresult)
206206

207207
raise OutOfBoundsDatetime(
208208
f"Cannot generate range with {side}={endpoint} and periods={periods}"

pandas/tests/frame/test_stack_unstack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
)
2222
import pandas._testing as tm
2323
from pandas.core.reshape import reshape as reshape_lib
24+
from pandas.compat import IS64
2425

2526

2627
@pytest.fixture(params=[True, False])
@@ -2092,6 +2093,7 @@ def test_unstack_unobserved_keys(self, future_stack):
20922093
tm.assert_frame_equal(recons, df)
20932094

20942095
@pytest.mark.slow
2096+
@pytest.mark.xfail(condition=not IS64, reason="assumes default int is int64")
20952097
def test_unstack_number_of_levels_larger_than_int32(self, monkeypatch):
20962098
# GH#20601
20972099
# GH 26314: Change ValueError to PerformanceWarning

pandas/tests/groupby/test_groupby.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import pytest
77

8+
from pandas.compat import IS64
89
from pandas.errors import (
910
PerformanceWarning,
1011
SpecificationError,
@@ -2545,6 +2546,7 @@ def test_groupby_series_with_tuple_name():
25452546
tm.assert_series_equal(result, expected)
25462547

25472548

2549+
@pytest.mark.xfail(not IS64, reason="GH#38778: fail on 32-bit system", strict=False)
25482550
@pytest.mark.parametrize(
25492551
"func, values", [("sum", [97.0, 98.0]), ("mean", [24.25, 24.5])]
25502552
)
@@ -2557,6 +2559,7 @@ def test_groupby_numerical_stability_sum_mean(func, values):
25572559
tm.assert_frame_equal(result, expected)
25582560

25592561

2562+
@pytest.mark.xfail(not IS64, reason="GH#38778: fail on 32-bit system", strict=False)
25602563
def test_groupby_numerical_stability_cumsum():
25612564
# GH#38934
25622565
data = [1e16, 1e16, 97, 98, -5e15, -5e15, -5e15, -5e15]

pandas/tests/reshape/test_pivot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from pandas.api.types import CategoricalDtype as CDT
2727
from pandas.core.reshape import reshape as reshape_lib
2828
from pandas.core.reshape.pivot import pivot_table
29+
from pandas.compat import IS64
2930

3031

3132
@pytest.fixture(params=[True, False])
@@ -2059,6 +2060,7 @@ def test_pivot_string_func_vs_func(self, f, f_numpy, data):
20592060
tm.assert_frame_equal(result, expected)
20602061

20612062
@pytest.mark.slow
2063+
@pytest.mark.xfail(condition=not IS64, reason="assumes default int is int64")
20622064
def test_pivot_number_of_levels_larger_than_int32(self, monkeypatch):
20632065
# GH 20601
20642066
# GH 26314: Change ValueError to PerformanceWarning

pandas/tests/series/methods/test_round.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def test_round_numpy(self, any_float_dtype):
3030
def test_round_numpy_with_nan(self, any_float_dtype):
3131
# See GH#14197
3232
ser = Series([1.53, np.nan, 0.06], dtype=any_float_dtype)
33-
with tm.assert_produces_warning(None):
34-
result = ser.round()
33+
result = ser.round() # on armhf, numpy warns
3534
expected = Series([2.0, np.nan, 0.0], dtype=any_float_dtype)
3635
tm.assert_series_equal(result, expected)
3736

pandas/tests/test_downstream.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
TimedeltaIndex,
2020
)
2121
import pandas._testing as tm
22+
from pandas.compat import IS64
2223
from pandas.core.arrays import (
2324
DatetimeArray,
2425
TimedeltaArray,
@@ -236,6 +237,11 @@ def test_missing_required_dependency():
236237
assert name in output
237238

238239

240+
@pytest.mark.xfail(
241+
condition=not IS64,
242+
reason="dask has different nativesize-int vs int64 type rules",
243+
strict=False,
244+
)
239245
def test_frame_setitem_dask_array_into_new_col():
240246
# GH#47128
241247

pandas/tests/test_sorting.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pandas.compat import (
99
is_ci_environment,
1010
is_platform_windows,
11+
IS64,
1112
)
1213

1314
from pandas import (
@@ -223,6 +224,7 @@ def test_int64_overflow_check_sum_col(self, left_right):
223224
assert result.name is None
224225

225226
@pytest.mark.slow
227+
@pytest.mark.xfail(condition=not IS64, reason="assumes default int is int64")
226228
@pytest.mark.parametrize("how", ["left", "right", "outer", "inner"])
227229
def test_int64_overflow_how_merge(self, left_right, how):
228230
left, right = left_right
@@ -233,6 +235,7 @@ def test_int64_overflow_how_merge(self, left_right, how):
233235
tm.assert_frame_equal(out, merge(left, right, how=how, sort=True))
234236

235237
@pytest.mark.slow
238+
@pytest.mark.xfail(condition=not IS64, reason="assumes default int is int64")
236239
def test_int64_overflow_sort_false_order(self, left_right):
237240
left, right = left_right
238241

@@ -244,6 +247,7 @@ def test_int64_overflow_sort_false_order(self, left_right):
244247
tm.assert_frame_equal(right, out[right.columns.tolist()])
245248

246249
@pytest.mark.slow
250+
@pytest.mark.xfail(condition=not IS64, reason="assumes default int is int64", strict=False)
247251
@pytest.mark.parametrize("how", ["left", "right", "outer", "inner"])
248252
@pytest.mark.parametrize("sort", [True, False])
249253
def test_int64_overflow_one_to_many_none_match(self, how, sort):

0 commit comments

Comments
 (0)