File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 8
8
Any ,
9
9
Callable ,
10
10
)
11
+ import warnings
11
12
12
13
import numpy as np
13
14
@@ -1694,7 +1695,12 @@ def pandas_dtype(dtype) -> DtypeObj:
1694
1695
# try a numpy dtype
1695
1696
# raise a consistent TypeError if failed
1696
1697
try :
1697
- npdtype = np .dtype (dtype )
1698
+ with warnings .catch_warnings ():
1699
+ # GH#51523 - Series.astype(np.integer) doesn't show
1700
+ # numpy deprication warning of np.integer
1701
+ # Hence enabling DeprecationWarning
1702
+ warnings .simplefilter ("always" , DeprecationWarning )
1703
+ npdtype = np .dtype (dtype )
1698
1704
except SyntaxError as err :
1699
1705
# np.dtype uses `eval` which can raise SyntaxError
1700
1706
raise TypeError (f"data type '{ dtype } ' not understood" ) from err
Original file line number Diff line number Diff line change @@ -754,3 +754,13 @@ def test_validate_allhashable():
754
754
755
755
with pytest .raises (TypeError , match = "list must be a hashable type" ):
756
756
com .validate_all_hashable ([], error_name = "list" )
757
+
758
+
759
+ def test_pandas_dtype_numpy_warning ():
760
+ # GH#51523
761
+ with tm .assert_produces_warning (
762
+ DeprecationWarning ,
763
+ check_stacklevel = False ,
764
+ match = "Converting `np.integer` or `np.signedinteger` to a dtype is deprecated" ,
765
+ ):
766
+ pandas_dtype (np .integer )
You can’t perform that action at this time.
0 commit comments