diff --git a/pandas/core/common.py b/pandas/core/common.py index 11c6d8ea1a821..6d419098bf279 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -32,6 +32,7 @@ import numpy as np from pandas._libs import lib +from pandas.compat.numpy import np_version_gte1p24 from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike from pandas.core.dtypes.common import ( @@ -236,7 +237,8 @@ def asarray_tuplesafe(values: Iterable, dtype: NpDtype | None = None) -> ArrayLi try: with warnings.catch_warnings(): # Can remove warning filter once NumPy 1.24 is min version - warnings.simplefilter("ignore", np.VisibleDeprecationWarning) + if not np_version_gte1p24: + warnings.simplefilter("ignore", np.VisibleDeprecationWarning) result = np.asarray(values, dtype=dtype) except ValueError: # Using try/except since it's more performant than checking is_list_like diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index e29fc12f118f4..05834b02a5ff3 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -13,6 +13,7 @@ import pytest from pandas.compat import IS64 +from pandas.compat.numpy import np_version_gte1p25 from pandas.core.dtypes.common import ( is_integer_dtype, @@ -389,7 +390,10 @@ def test_astype_preserves_name(self, index, dtype): warn = None if index.dtype.kind == "c" and dtype in ["float64", "int64", "uint64"]: # imaginary components discarded - warn = np.ComplexWarning + if np_version_gte1p25: + warn = np.exceptions.ComplexWarning + else: + warn = np.ComplexWarning is_pyarrow_str = str(index.dtype) == "string[pyarrow]" and dtype == "category" try: