File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -1836,6 +1836,8 @@ def pandas_dtype(dtype) -> DtypeObj:
1836
1836
# raise a consistent TypeError if failed
1837
1837
try :
1838
1838
with warnings .catch_warnings ():
1839
+ # TODO: warnings.catch_warnings can be removed when numpy>2.2.2
1840
+ # is the minimum version
1839
1841
# GH#51523 - Series.astype(np.integer) doesn't show
1840
1842
# numpy deprecation warning of np.integer
1841
1843
# Hence enabling DeprecationWarning
Original file line number Diff line number Diff line change 22
22
import pandas ._testing as tm
23
23
from pandas .api .types import pandas_dtype
24
24
from pandas .arrays import SparseArray
25
+ from pandas .util .version import Version
25
26
26
27
27
28
# EA & Actual Dtypes
@@ -788,11 +789,18 @@ def test_validate_allhashable():
788
789
789
790
def test_pandas_dtype_numpy_warning ():
790
791
# 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 :
796
804
pandas_dtype (np .integer )
797
805
798
806
You can’t perform that action at this time.
0 commit comments