Skip to content

Commit 5b16c06

Browse files
authored
TST/CI: Address enforced numpy DeprecationWarning in test_pandas_dtype_numpy_warning (#60875)
TST: Address enforced numpy DeprecationWarning in test_pandas_dtype_numpy_warning
1 parent 0d85d57 commit 5b16c06

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Diff for: pandas/core/dtypes/common.py

+2
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,8 @@ def pandas_dtype(dtype) -> DtypeObj:
18361836
# raise a consistent TypeError if failed
18371837
try:
18381838
with warnings.catch_warnings():
1839+
# TODO: warnings.catch_warnings can be removed when numpy>2.2.2
1840+
# is the minimum version
18391841
# GH#51523 - Series.astype(np.integer) doesn't show
18401842
# numpy deprecation warning of np.integer
18411843
# Hence enabling DeprecationWarning

Diff for: pandas/tests/dtypes/test_common.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import pandas._testing as tm
2323
from pandas.api.types import pandas_dtype
2424
from pandas.arrays import SparseArray
25+
from pandas.util.version import Version
2526

2627

2728
# EA & Actual Dtypes
@@ -788,11 +789,18 @@ def test_validate_allhashable():
788789

789790
def test_pandas_dtype_numpy_warning():
790791
# GH#51523
791-
with tm.assert_produces_warning(
792-
DeprecationWarning,
793-
check_stacklevel=False,
794-
match="Converting `np.integer` or `np.signedinteger` to a dtype is deprecated",
795-
):
792+
if Version(np.__version__) <= Version("2.2.2"):
793+
ctx = tm.assert_produces_warning(
794+
DeprecationWarning,
795+
check_stacklevel=False,
796+
match=(
797+
"Converting `np.integer` or `np.signedinteger` to a dtype is deprecated"
798+
),
799+
)
800+
else:
801+
ctx = tm.external_error_raised(TypeError)
802+
803+
with ctx:
796804
pandas_dtype(np.integer)
797805

798806

0 commit comments

Comments
 (0)