Skip to content

Commit 4362824

Browse files
committed
ENH: Update numpy exceptions imports
1 parent 92d1d6a commit 4362824

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pandas/core/common.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
)
4646
from pandas.core.dtypes.inference import iterable_not_string
4747

48+
from pandas.util.version import Version
49+
4850
if TYPE_CHECKING:
4951
from pandas._typing import (
5052
AnyArrayLike,
@@ -236,7 +238,8 @@ def asarray_tuplesafe(values: Iterable, dtype: NpDtype | None = None) -> ArrayLi
236238
try:
237239
with warnings.catch_warnings():
238240
# Can remove warning filter once NumPy 1.24 is min version
239-
warnings.simplefilter("ignore", np.VisibleDeprecationWarning)
241+
if Version(np.__version__) < Version("1.24.0"):
242+
warnings.simplefilter("ignore", np.VisibleDeprecationWarning)
240243
result = np.asarray(values, dtype=dtype)
241244
except ValueError:
242245
# 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
@@ -27,6 +27,7 @@
2727
RangeIndex,
2828
)
2929
import pandas._testing as tm
30+
from pandas.util.version import Version
3031

3132

3233
class TestCommon:
@@ -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 Version(np.__version__) >= Version("1.25.0"):
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)