Skip to content

Commit f501fd6

Browse files
mroeschkemeeseeksmachine
authored andcommitted
Backport PR pandas-dev#60875: TST/CI: Address enforced numpy DeprecationWarning in test_pandas_dtype_numpy_warning
1 parent e3df72a commit f501fd6

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

pandas/core/dtypes/common.py

+2
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,8 @@ def pandas_dtype(dtype) -> DtypeObj:
16541654
# raise a consistent TypeError if failed
16551655
try:
16561656
with warnings.catch_warnings():
1657+
# TODO: warnings.catch_warnings can be removed when numpy>2.2.2
1658+
# is the minimum version
16571659
# GH#51523 - Series.astype(np.integer) doesn't show
16581660
# numpy deprecation warning of np.integer
16591661
# Hence enabling DeprecationWarning

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)