Skip to content

Commit 78c79b9

Browse files
authored
ENH: Update numpy exceptions imports (#54405)
* ENH: Update numpy exceptions imports * ENH: Use version checks from dedicated utils
1 parent fac929f commit 78c79b9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pandas/core/common.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import numpy as np
3333

3434
from pandas._libs import lib
35+
from pandas.compat.numpy import np_version_gte1p24
3536

3637
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
3738
from pandas.core.dtypes.common import (
@@ -236,7 +237,8 @@ def asarray_tuplesafe(values: Iterable, dtype: NpDtype | None = None) -> ArrayLi
236237
try:
237238
with warnings.catch_warnings():
238239
# Can remove warning filter once NumPy 1.24 is min version
239-
warnings.simplefilter("ignore", np.VisibleDeprecationWarning)
240+
if not np_version_gte1p24:
241+
warnings.simplefilter("ignore", np.VisibleDeprecationWarning)
240242
result = np.asarray(values, dtype=dtype)
241243
except ValueError:
242244
# Using try/except since it's more performant than checking is_list_like

pandas/tests/indexes/test_common.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import pytest
1414

1515
from pandas.compat import IS64
16+
from pandas.compat.numpy import np_version_gte1p25
1617

1718
from pandas.core.dtypes.common import (
1819
is_integer_dtype,
@@ -389,7 +390,10 @@ def test_astype_preserves_name(self, index, dtype):
389390
warn = None
390391
if index.dtype.kind == "c" and dtype in ["float64", "int64", "uint64"]:
391392
# imaginary components discarded
392-
warn = np.ComplexWarning
393+
if np_version_gte1p25:
394+
warn = np.exceptions.ComplexWarning
395+
else:
396+
warn = np.ComplexWarning
393397

394398
is_pyarrow_str = str(index.dtype) == "string[pyarrow]" and dtype == "category"
395399
try:

0 commit comments

Comments
 (0)