Skip to content

BUG: Series.astype(np.integer) doesn't show numpy warning #51523

Closed
@Dr-Irv

Description

@Dr-Irv

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '2.1.0.dev0+5.g8d2a4e11d1'

In [3]: import numpy as np

In [4]: np.__version__
Out[4]: '1.23.5'

In [5]: s = pd.Series([1,2,3])

In [6]: s.astype(np.integer)
Out[6]:
0    1
1    2
2    3
dtype: int32

In [7]: np.dtype(np.integer)
<ipython-input-7-c11ccc0059df>:1: DeprecationWarning: Converting `np.integer` or `np.signedinteger` to a dtype is deprecated. The current result is `np.dtype(np.int_)` which is not strictly correct. Note that the result depends on the system. To ensure stable results use may want to use `np.int64` or `np.int32`.
  np.dtype(np.integer)
Out[7]: dtype('int32')

In [8]: from pandas.core.dtypes.common import pandas_dtype

In [9]: pandas_dtype(np.integer)
Out[9]: dtype('int32')

Issue Description

For some reason, if you call Series.astype(np.integer), the warning from numpy about calling np.dtype(np.integer) is suppressed.

This came up in some pandas-stubs testing. pandas.core.dtypes.common.pandas_dtype() calles np.dtype(), but we don't print the deprecation warning.

The way we saw it is that it got printed by pytest

Expected Behavior

We should print the numpy deprecation warning.

Installed Versions

INSTALLED VERSIONS

commit : 8d2a4e1
python : 3.8.16.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 2.1.0.dev0+5.g8d2a4e11d1
numpy : 1.23.5
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 66.1.1
pip : 23.0
Cython : 0.29.32
pytest : 7.2.1
hypothesis : 6.68.1
sphinx : 4.5.0
blosc : None
feather : None
xlsxwriter : 3.0.8
lxml.etree : 4.9.2
html5lib : 1.1
pymysql : 1.0.2
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : 8.10.0
pandas_datareader: None
bs4 : 4.11.2
bottleneck : 1.3.6
brotli :
fastparquet : 2023.2.0
fsspec : 2023.1.0
gcsfs : 2023.1.0
matplotlib : 3.6.3
numba : 0.56.4
numexpr : 2.8.3
odfpy : None
openpyxl : 3.1.0
pandas_gbq : None
pyarrow : 10.0.1
pyreadstat : 1.2.0
pyxlsb : 1.0.10
s3fs : 2023.1.0
scipy : 1.10.0
snappy :
sqlalchemy : 2.0.3
tables : 3.7.0
tabulate : 0.9.0
xarray : 2023.1.0
xlrd : 2.0.1
zstandard : 0.19.0
tzdata : None
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

BugWarningsWarnings that appear or should be added to pandas

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions