Skip to content

TST: Fix some test builds for numpy 2.0 #59046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/deps/actions-311-pyarrownightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:

# required dependencies
- python-dateutil
- numpy
- numpy<2
- pytz
- pip

Expand Down
2 changes: 2 additions & 0 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
pa_version_under14p0,
pa_version_under14p1,
pa_version_under16p0,
pa_version_under17p0,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -154,6 +155,7 @@ def is_ci_environment() -> bool:
"pa_version_under14p0",
"pa_version_under14p1",
"pa_version_under16p0",
"pa_version_under17p0",
"IS64",
"ISMUSL",
"PY311",
Expand Down
2 changes: 1 addition & 1 deletion pandas/compat/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
np_version_gte1p24 = _nlv >= Version("1.24")
np_version_gte1p24p3 = _nlv >= Version("1.24.3")
np_version_gte1p25 = _nlv >= Version("1.25")
np_version_gt2 = _nlv >= Version("2.0.0.dev0")
np_version_gt2 = _nlv >= Version("2.0.0")
is_numpy_dev = _nlv.dev is not None
_min_numpy_ver = "1.23.5"

Expand Down
2 changes: 2 additions & 0 deletions pandas/compat/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
pa_version_under14p1 = _palv < Version("14.0.1")
pa_version_under15p0 = _palv < Version("15.0.0")
pa_version_under16p0 = _palv < Version("16.0.0")
pa_version_under17p0 = _palv < Version("17.0.0")
except ImportError:
pa_version_under10p1 = True
pa_version_under11p0 = True
Expand All @@ -25,3 +26,4 @@
pa_version_under14p1 = True
pa_version_under15p0 = True
pa_version_under16p0 = True
pa_version_under17p0 = True
13 changes: 5 additions & 8 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
is_supported_dtype,
)
from pandas._libs.tslibs.timedeltas import array_to_timedelta64
from pandas.compat.numpy import np_version_gt2
from pandas.errors import (
IntCastingNaNError,
LossySetitemError,
Expand Down Expand Up @@ -1643,13 +1642,11 @@ def maybe_cast_to_integer_array(arr: list | np.ndarray, dtype: np.dtype) -> np.n
with warnings.catch_warnings():
# We already disallow dtype=uint w/ negative numbers
# (test_constructor_coercion_signed_to_unsigned) so safe to ignore.
if not np_version_gt2:
warnings.filterwarnings(
"ignore",
"NumPy will stop allowing conversion of "
"out-of-bound Python int",
DeprecationWarning,
)
warnings.filterwarnings(
"ignore",
"NumPy will stop allowing conversion of " "out-of-bound Python int",
DeprecationWarning,
)
casted = np.asarray(arr, dtype=dtype)
else:
with warnings.catch_warnings():
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimelike_/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@pytest.mark.parametrize("ldtype", dtlike_dtypes)
@pytest.mark.parametrize("rdtype", dtlike_dtypes)
def test_get_indexer_non_unique_wrong_dtype(ldtype, rdtype):
vals = np.tile(3600 * 10**9 * np.arange(3), 2)
vals = np.tile(3600 * 10**9 * np.arange(3, dtype=np.int64), 2)

def construct(dtype):
if dtype is dtlike_dtypes[-1]:
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
pa_version_under11p0,
pa_version_under13p0,
pa_version_under15p0,
pa_version_under17p0,
)

import pandas as pd
Expand Down Expand Up @@ -1033,7 +1034,9 @@ def test_read_dtype_backend_pyarrow_config_index(self, pa):
expected=expected,
)

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

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/scalar/timedelta/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def test_td_mul_numeric_ndarray(self):

def test_td_mul_numeric_ndarray_0d(self):
td = Timedelta("1 day")
other = np.array(2)
other = np.array(2, dtype=np.int64)
assert other.ndim == 0
expected = Timedelta("2 days")

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/tools/test_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3187,7 +3187,7 @@ def test_invalid_origin(self, unit):
)
def test_epoch(self, units, epochs):
epoch_1960 = Timestamp(1960, 1, 1)
units_from_epochs = list(range(5))
units_from_epochs = np.arange(5, dtype=np.int64)
expected = Series(
[pd.Timedelta(x, unit=units) + epoch_1960 for x in units_from_epochs]
)
Expand Down