Skip to content

Commit 5be45c2

Browse files
phoflmroeschke
andauthored
CI: Test numpy 1.24 on 3.11 build (#51006)
* CI: Add complete build with 1.24 numpy * Change * Revert "Change" This reverts commit 993dec4. * Revert "CI: Add complete build with 1.24 numpy" This reverts commit b58c1da. * Change 3.11 build * Fix some tests * Fix * Fix * Fix some warnings * Fix tests * Add reason * Fix windows ci * Fix * Update ci/deps/actions-311.yaml Co-authored-by: Matthew Roeschke <[email protected]> * Add warning category * Update test_frame_subplots.py * Update test_series.py --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 52306d9 commit 5be45c2

File tree

10 files changed

+72
-23
lines changed

10 files changed

+72
-23
lines changed

ci/deps/actions-311.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<1.24.0
21+
- numpy
2222
- pytz
2323

2424
# optional dependencies

pandas/compat/numpy/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
np_version_under1p21 = _nlv < Version("1.21")
1010
np_version_under1p22 = _nlv < Version("1.22")
1111
np_version_gte1p22 = _nlv >= Version("1.22")
12+
np_version_gte1p24 = _nlv >= Version("1.24")
1213
is_numpy_dev = _nlv.dev is not None
1314
_min_numpy_ver = "1.20.3"
1415

pandas/core/arrays/masked.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,14 @@ def to_numpy(
428428
"for this dtype."
429429
)
430430
# don't pass copy to astype -> always need a copy since we are mutating
431-
data = self._data.astype(dtype)
431+
with warnings.catch_warnings():
432+
warnings.filterwarnings("ignore", category=RuntimeWarning)
433+
data = self._data.astype(dtype)
432434
data[self._mask] = na_value
433435
else:
434-
data = self._data.astype(dtype, copy=copy)
436+
with warnings.catch_warnings():
437+
warnings.filterwarnings("ignore", category=RuntimeWarning)
438+
data = self._data.astype(dtype, copy=copy)
435439
return data
436440

437441
@doc(ExtensionArray.tolist)
@@ -464,7 +468,10 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike:
464468
# if we are astyping to another nullable masked dtype, we can fastpath
465469
if isinstance(dtype, BaseMaskedDtype):
466470
# TODO deal with NaNs for FloatingArray case
467-
data = self._data.astype(dtype.numpy_dtype, copy=copy)
471+
with warnings.catch_warnings():
472+
warnings.filterwarnings("ignore", category=RuntimeWarning)
473+
# TODO: Is rounding what we want long term?
474+
data = self._data.astype(dtype.numpy_dtype, copy=copy)
468475
# mask is copied depending on whether the data was copied, and
469476
# not directly depending on the `copy` keyword
470477
mask = self._mask if data is self._data else self._mask.copy()

pandas/core/arrays/timedeltas.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Iterator,
88
cast,
99
)
10+
import warnings
1011

1112
import numpy as np
1213

@@ -918,11 +919,20 @@ def sequence_to_td64ns(
918919
mask = np.isnan(data)
919920
# The next few lines are effectively a vectorized 'cast_from_unit'
920921
m, p = precision_from_unit(unit or "ns")
921-
base = data.astype(np.int64)
922+
with warnings.catch_warnings():
923+
# Suppress RuntimeWarning about All-NaN slice
924+
warnings.filterwarnings(
925+
"ignore", "invalid value encountered in cast", RuntimeWarning
926+
)
927+
base = data.astype(np.int64)
922928
frac = data - base
923929
if p:
924930
frac = np.round(frac, p)
925-
data = (base * m + (frac * m).astype(np.int64)).view("timedelta64[ns]")
931+
with warnings.catch_warnings():
932+
warnings.filterwarnings(
933+
"ignore", "invalid value encountered in cast", RuntimeWarning
934+
)
935+
data = (base * m + (frac * m).astype(np.int64)).view("timedelta64[ns]")
926936
data[mask] = iNaT
927937
copy = False
928938

pandas/core/dtypes/astype.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
TYPE_CHECKING,
1010
overload,
1111
)
12+
import warnings
1213

1314
import numpy as np
1415

@@ -154,7 +155,9 @@ def _astype_float_to_int_nansafe(
154155
# GH#45151
155156
if not (values >= 0).all():
156157
raise ValueError(f"Cannot losslessly cast from {values.dtype} to {dtype}")
157-
return values.astype(dtype, copy=copy)
158+
with warnings.catch_warnings():
159+
warnings.filterwarnings("ignore", category=RuntimeWarning)
160+
return values.astype(dtype, copy=copy)
158161

159162

160163
def astype_array(values: ArrayLike, dtype: DtypeObj, copy: bool = False) -> ArrayLike:

pandas/core/dtypes/cast.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ def trans(x):
398398
and not is_bool_dtype(result.dtype)
399399
and not is_string_dtype(result.dtype)
400400
):
401-
new_result = result.astype(dtype)
401+
with warnings.catch_warnings():
402+
warnings.filterwarnings(
403+
"ignore", "overflow encountered in cast", RuntimeWarning
404+
)
405+
new_result = result.astype(dtype)
402406

403407
# Adjust tolerances based on floating point size
404408
size_tols = {4: 5e-4, 8: 5e-8, 16: 5e-16}
@@ -1602,7 +1606,9 @@ def maybe_cast_to_integer_array(arr: list | np.ndarray, dtype: np.dtype) -> np.n
16021606
)
16031607
casted = np.array(arr, dtype=dtype, copy=False)
16041608
else:
1605-
casted = arr.astype(dtype, copy=False)
1609+
with warnings.catch_warnings():
1610+
warnings.filterwarnings("ignore", category=RuntimeWarning)
1611+
casted = arr.astype(dtype, copy=False)
16061612
except OverflowError as err:
16071613
raise OverflowError(
16081614
"The elements provided in the data cannot all be "
@@ -1614,7 +1620,7 @@ def maybe_cast_to_integer_array(arr: list | np.ndarray, dtype: np.dtype) -> np.n
16141620
return casted
16151621

16161622
with warnings.catch_warnings():
1617-
warnings.filterwarnings("ignore")
1623+
warnings.filterwarnings("ignore", category=RuntimeWarning)
16181624
if np.array_equal(arr, casted):
16191625
return casted
16201626

@@ -1817,7 +1823,9 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any:
18171823
# see test_where_complex GH#6345
18181824
return dtype.type(element)
18191825

1820-
casted = dtype.type(element)
1826+
with warnings.catch_warnings():
1827+
warnings.filterwarnings("ignore")
1828+
casted = dtype.type(element)
18211829
if casted == element:
18221830
return casted
18231831
# otherwise e.g. overflow see test_32878_complex_itemsize

pandas/core/indexes/base.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -3865,9 +3865,15 @@ def _get_fill_indexer(
38653865
# but that doesn't appear to be enforced
38663866
# error: "IndexEngine" has no attribute "get_indexer_with_fill"
38673867
engine = self._engine
3868-
return engine.get_indexer_with_fill( # type: ignore[union-attr]
3869-
target=target._values, values=self._values, method=method, limit=limit
3870-
)
3868+
with warnings.catch_warnings():
3869+
# TODO: We need to fix this. Casting to int64 in cython
3870+
warnings.filterwarnings("ignore", category=RuntimeWarning)
3871+
return engine.get_indexer_with_fill( # type: ignore[union-attr]
3872+
target=target._values,
3873+
values=self._values,
3874+
method=method,
3875+
limit=limit,
3876+
)
38713877

38723878
if self.is_monotonic_increasing and target.is_monotonic_increasing:
38733879
target_values = target._get_engine_target()

pandas/tests/extension/test_period.py

+11
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
import pytest
1818

1919
from pandas._libs import iNaT
20+
from pandas.compat import is_platform_windows
21+
from pandas.compat.numpy import np_version_gte1p24
2022

2123
from pandas.core.dtypes.dtypes import PeriodDtype
2224

2325
import pandas as pd
26+
import pandas._testing as tm
2427
from pandas.core.arrays import PeriodArray
2528
from pandas.tests.extension import base
2629

@@ -94,6 +97,14 @@ def test_combine_add(self, data_repeated):
9497
# Period + Period is not defined.
9598
pass
9699

100+
@pytest.mark.parametrize("periods", [1, -2])
101+
def test_diff(self, data, periods):
102+
if is_platform_windows() and np_version_gte1p24:
103+
with tm.assert_produces_warning(RuntimeWarning, check_stacklevel=False):
104+
super().test_diff(data, periods)
105+
else:
106+
super().test_diff(data, periods)
107+
97108

98109
class TestInterface(BasePeriodTests, base.BaseInterfaceTests):
99110

pandas/tests/io/parser/test_c_parser_only.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
IS64,
2222
is_ci_environment,
2323
)
24+
from pandas.compat.numpy import np_version_gte1p24
2425
from pandas.errors import ParserError
2526
import pandas.util._test_decorators as td
2627

@@ -114,14 +115,16 @@ def test_dtype_and_names_error(c_parser_only):
114115
3.0 3
115116
"""
116117
# fallback casting, but not castable
118+
warning = RuntimeWarning if np_version_gte1p24 else None
117119
with pytest.raises(ValueError, match="cannot safely convert"):
118-
parser.read_csv(
119-
StringIO(data),
120-
sep=r"\s+",
121-
header=None,
122-
names=["a", "b"],
123-
dtype={"a": np.int32},
124-
)
120+
with tm.assert_produces_warning(warning, check_stacklevel=False):
121+
parser.read_csv(
122+
StringIO(data),
123+
sep=r"\s+",
124+
header=None,
125+
names=["a", "b"],
126+
dtype={"a": np.int32},
127+
)
125128

126129

127130
@pytest.mark.parametrize(

pandas/tests/series/test_constructors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ def test_constructor_floating_data_int_dtype(self, frame_or_series):
804804
# Long-standing behavior (for Series, new in 2.0 for DataFrame)
805805
# has been to ignore the dtype on these;
806806
# not clear if this is what we want long-term
807-
expected = frame_or_series(arr)
807+
# expected = frame_or_series(arr)
808808

809809
# GH#49599 as of 2.0 we raise instead of silently retaining float dtype
810810
msg = "Trying to coerce float values to integer"
@@ -816,7 +816,7 @@ def test_constructor_floating_data_int_dtype(self, frame_or_series):
816816

817817
# pre-2.0, when we had NaNs, we silently ignored the integer dtype
818818
arr[0] = np.nan
819-
expected = frame_or_series(arr)
819+
# expected = frame_or_series(arr)
820820

821821
msg = r"Cannot convert non-finite values \(NA or inf\) to integer"
822822
with pytest.raises(IntCastingNaNError, match=msg):

0 commit comments

Comments
 (0)