Skip to content

Commit 2a1417a

Browse files
authored
Backport PR #59046: TST: Fix some test builds for numpy 2.0 (#59086)
1 parent 8882959 commit 2a1417a

File tree

9 files changed

+29
-13
lines changed

9 files changed

+29
-13
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:
@@ -188,6 +189,7 @@ def get_bz2_file() -> type[pandas.compat.compressors.BZ2File]:
188189
"pa_version_under14p0",
189190
"pa_version_under14p1",
190191
"pa_version_under16p0",
192+
"pa_version_under17p0",
191193
"IS64",
192194
"ISMUSL",
193195
"PY310",

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.22.4"
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,
@@ -1647,13 +1646,11 @@ def maybe_cast_to_integer_array(arr: list | np.ndarray, dtype: np.dtype) -> np.n
16471646
with warnings.catch_warnings():
16481647
# We already disallow dtype=uint w/ negative numbers
16491648
# (test_constructor_coercion_signed_to_unsigned) so safe to ignore.
1650-
if not np_version_gt2:
1651-
warnings.filterwarnings(
1652-
"ignore",
1653-
"NumPy will stop allowing conversion of "
1654-
"out-of-bound Python int",
1655-
DeprecationWarning,
1656-
)
1649+
warnings.filterwarnings(
1650+
"ignore",
1651+
"NumPy will stop allowing conversion of out-of-bound Python int",
1652+
DeprecationWarning,
1653+
)
16571654
casted = np.asarray(arr, dtype=dtype)
16581655
else:
16591656
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
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
pa_version_under11p0,
1717
pa_version_under13p0,
1818
pa_version_under15p0,
19+
pa_version_under17p0,
1920
)
2021

2122
import pandas as pd
@@ -1063,6 +1064,9 @@ def test_read_dtype_backend_pyarrow_config_index(self, pa):
10631064
expected=expected,
10641065
)
10651066

1067+
@pytest.mark.xfail(
1068+
pa_version_under17p0, reason="pa.pandas_compat passes 'datetime64' to .astype"
1069+
)
10661070
def test_columns_dtypes_not_invalid(self, pa):
10671071
df = pd.DataFrame({"string": list("abc"), "int": list(range(1, 4))})
10681072

pandas/tests/scalar/timedelta/test_arithmetic.py

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

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

pandas/tests/tools/test_to_datetime.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,18 @@ def test_invalid_origin(self, unit):
34073407
with pytest.raises(ValueError, match=msg):
34083408
to_datetime("2005-01-01", origin="1960-01-01", unit=unit)
34093409

3410-
def test_epoch(self, units, epochs, epoch_1960, units_from_epochs):
3410+
@pytest.mark.parametrize(
3411+
"epochs",
3412+
[
3413+
Timestamp(1960, 1, 1),
3414+
datetime(1960, 1, 1),
3415+
"1960-01-01",
3416+
np.datetime64("1960-01-01"),
3417+
],
3418+
)
3419+
def test_epoch(self, units, epochs):
3420+
epoch_1960 = Timestamp(1960, 1, 1)
3421+
units_from_epochs = np.arange(5, dtype=np.int64)
34113422
expected = Series(
34123423
[pd.Timedelta(x, unit=units) + epoch_1960 for x in units_from_epochs]
34133424
)

0 commit comments

Comments
 (0)