Pandas version checks

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

  • [X] 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

from cyberpandas import IPArray
import pandas as pd
import numpy as np

# Create a dataframe to extract the `IPType` (I'm sure this can be shortened)
df = pd.DataFrame({
    'address': IPArray(['192.168.1.1', '192.168.1.10'])
})

ipdtype = df['address'].dtype

np.issubdtype(ipdtype, np.int64)

raises

Traceback (most recent call last):
  File "foo.py", line 13, in <module>
    np.issubdtype(ipdtype, np.int64)
  File "./venv/lib64/python3.8/site-packages/numpy/core/numerictypes.py", line 416, in issubdtype
    arg1 = dtype(arg1).type
TypeError: Cannot interpret '<cyberpandas.ip_array.IPType object at 0x7fd1dddb1640>' as a data type

Issue Description

np.issubdtype(...) raises an error for EADtype. I found this https://github.com/pandas-dev/pandas/issues/27953 closed ticket which suggests that np.issubdtype should work, but I haven't had a chance to check how this was solved for CategoricalDtype (or if it's still working).

Expected Behavior

No exception, normal behaviour as other dtypes

Installed Versions

INSTALLED VERSIONS ------------------ commit : e8093ba372f9adfe79439d90fe74b0b5b6dea9d6 python : 3.8.13.final.0 python-bits : 64 OS : Linux OS-release : 5.18.17-200.fc36.x86_64 Version : #1 SMP PREEMPT_DYNAMIC Thu Aug 11 14:36:06 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_AU.UTF-8 LOCALE : en_AU.UTF-8 pandas : 1.4.3 numpy : 1.23.2 pytz : 2022.2.1 dateutil : 2.8.2 setuptools : 59.6.0 pip : 21.3.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : None markupsafe : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None snappy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None

Comment From: Runningwater2357

Modify the issubtype method of numerictypes.py as follows:

@set_module('numpy')
def issubdtype(arg1, arg2):
    if not issubclass_(arg1, generic):
        if hasattr(arg1, 'type'):
            arg1 = arg1.type
        else:
            return False
    if not issubclass_(arg2, generic):
        arg2 = dtype(arg2).type

    return issubclass(arg1, arg2)

If arg1 is of the numpy data type and contains the type attribute, the subtype can be identified normally. (The NumPy data type has been tested and the function is normal.) If arg1 is not a numpy data type and does not have the type attribute, it must not be a numpy subtype. In this case, false is returned. If the type attribute exists, the system directly determines whether the type of arg1 is a subclass of the arg2 type. This does not cause abnormal running.

Comment From: jbrockmendel

[...] https://github.com/pandas-dev/pandas/issues/27953 closed ticket which suggests that np.issubdtype should work

That isn't about np.issubdtype, but about a pandas constructor. We wouldn't except np.issubdtype to work on anything other than numpy dtypes.

Comment From: ssche

Fair enough - I think I got confused with #27953.

I was just looking for a function that is checking the dtype in a Numpy dtype/EA dtype agnostic manner. With your explanation, I assume this snippet works because the dtype happens to be a Numpy dtype.

>>> import numpy as np
>>> import pandas as pd
>>> 
>>> df = pd.DataFrame({'a': [1, 2, 3]})
>>> 
>>> np.issubdtype(df['a'].dtype, np.int64)
True