Skip to content

Commit b1e5f06

Browse files
authored
TST: Fix some test builds for numpy 2.0 (#59046)
* TST: Fix some test builds for numpy 2.0 * 64 not 32 * Adjust some tests * Revert "Adjust some tests" This reverts commit ca28f25. * Just pin numpy in pyarrow nightly build * Mark test as pa under 17
1 parent 0b45a6e commit b1e5f06

File tree

9 files changed

+18
-14
lines changed

9 files changed

+18
-14
lines changed

ci/deps/actions-311-pyarrownightly.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818

1919
# required dependencies
2020
- python-dateutil
21-
- numpy
21+
- numpy<2
2222
- pytz
2323
- pip
2424

pandas/compat/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
pa_version_under14p0,
3232
pa_version_under14p1,
3333
pa_version_under16p0,
34+
pa_version_under17p0,
3435
)
3536

3637
if TYPE_CHECKING:
@@ -154,6 +155,7 @@ def is_ci_environment() -> bool:
154155
"pa_version_under14p0",
155156
"pa_version_under14p1",
156157
"pa_version_under16p0",
158+
"pa_version_under17p0",
157159
"IS64",
158160
"ISMUSL",
159161
"PY311",

pandas/compat/numpy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
np_version_gte1p24 = _nlv >= Version("1.24")
1313
np_version_gte1p24p3 = _nlv >= Version("1.24.3")
1414
np_version_gte1p25 = _nlv >= Version("1.25")
15-
np_version_gt2 = _nlv >= Version("2.0.0.dev0")
15+
np_version_gt2 = _nlv >= Version("2.0.0")
1616
is_numpy_dev = _nlv.dev is not None
1717
_min_numpy_ver = "1.23.5"
1818

pandas/compat/pyarrow.py

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
pa_version_under14p1 = _palv < Version("14.0.1")
1717
pa_version_under15p0 = _palv < Version("15.0.0")
1818
pa_version_under16p0 = _palv < Version("16.0.0")
19+
pa_version_under17p0 = _palv < Version("17.0.0")
1920
except ImportError:
2021
pa_version_under10p1 = True
2122
pa_version_under11p0 = True
@@ -25,3 +26,4 @@
2526
pa_version_under14p1 = True
2627
pa_version_under15p0 = True
2728
pa_version_under16p0 = True
29+
pa_version_under17p0 = True

pandas/core/dtypes/cast.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
is_supported_dtype,
4040
)
4141
from pandas._libs.tslibs.timedeltas import array_to_timedelta64
42-
from pandas.compat.numpy import np_version_gt2
4342
from pandas.errors import (
4443
IntCastingNaNError,
4544
LossySetitemError,
@@ -1643,13 +1642,11 @@ def maybe_cast_to_integer_array(arr: list | np.ndarray, dtype: np.dtype) -> np.n
16431642
with warnings.catch_warnings():
16441643
# We already disallow dtype=uint w/ negative numbers
16451644
# (test_constructor_coercion_signed_to_unsigned) so safe to ignore.
1646-
if not np_version_gt2:
1647-
warnings.filterwarnings(
1648-
"ignore",
1649-
"NumPy will stop allowing conversion of "
1650-
"out-of-bound Python int",
1651-
DeprecationWarning,
1652-
)
1645+
warnings.filterwarnings(
1646+
"ignore",
1647+
"NumPy will stop allowing conversion of " "out-of-bound Python int",
1648+
DeprecationWarning,
1649+
)
16531650
casted = np.asarray(arr, dtype=dtype)
16541651
else:
16551652
with warnings.catch_warnings():

pandas/tests/indexes/datetimelike_/test_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@pytest.mark.parametrize("ldtype", dtlike_dtypes)
2020
@pytest.mark.parametrize("rdtype", dtlike_dtypes)
2121
def test_get_indexer_non_unique_wrong_dtype(ldtype, rdtype):
22-
vals = np.tile(3600 * 10**9 * np.arange(3), 2)
22+
vals = np.tile(3600 * 10**9 * np.arange(3, dtype=np.int64), 2)
2323

2424
def construct(dtype):
2525
if dtype is dtlike_dtypes[-1]:

pandas/tests/io/test_parquet.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
pa_version_under11p0,
1515
pa_version_under13p0,
1616
pa_version_under15p0,
17+
pa_version_under17p0,
1718
)
1819

1920
import pandas as pd
@@ -1033,7 +1034,9 @@ def test_read_dtype_backend_pyarrow_config_index(self, pa):
10331034
expected=expected,
10341035
)
10351036

1036-
@pytest.mark.xfail(reason="pa.pandas_compat passes 'datetime64' to .astype")
1037+
@pytest.mark.xfail(
1038+
pa_version_under17p0, reason="pa.pandas_compat passes 'datetime64' to .astype"
1039+
)
10371040
def test_columns_dtypes_not_invalid(self, pa):
10381041
df = pd.DataFrame({"string": list("abc"), "int": list(range(1, 4))})
10391042

pandas/tests/scalar/timedelta/test_arithmetic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def test_td_mul_numeric_ndarray(self):
419419

420420
def test_td_mul_numeric_ndarray_0d(self):
421421
td = Timedelta("1 day")
422-
other = np.array(2)
422+
other = np.array(2, dtype=np.int64)
423423
assert other.ndim == 0
424424
expected = Timedelta("2 days")
425425

pandas/tests/tools/test_to_datetime.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3187,7 +3187,7 @@ def test_invalid_origin(self, unit):
31873187
)
31883188
def test_epoch(self, units, epochs):
31893189
epoch_1960 = Timestamp(1960, 1, 1)
3190-
units_from_epochs = list(range(5))
3190+
units_from_epochs = np.arange(5, dtype=np.int64)
31913191
expected = Series(
31923192
[pd.Timedelta(x, unit=units) + epoch_1960 for x in units_from_epochs]
31933193
)

0 commit comments

Comments
 (0)