Content-Length: 234173 | pFad | https://github.com/numpy/numpy/issues/28946

95 BUG: dtype `datetime64[ns, UTC]` not interpreted by `issubdtype` · Issue #28946 · numpy/numpy · GitHub
Skip to content

BUG: dtype datetime64[ns, UTC] not interpreted by issubdtype #28946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
johannes-mueller opened this issue May 12, 2025 · 1 comment
Open

BUG: dtype datetime64[ns, UTC] not interpreted by issubdtype #28946

johannes-mueller opened this issue May 12, 2025 · 1 comment
Labels

Comments

@johannes-mueller
Copy link

johannes-mueller commented May 12, 2025

Describe the issue:

This is more or less the same as reported in #19187 and allegedly fixed. But it does still occur in the version combinations I tested with (see below).

Reproduce the code example:

import pandas as pd
import numpy as np

dtype = pd.date_range("2016-01-01", periods=2, tz="UTC").dtype

np.issubdtype(dtype, np.number)

Error message:

Traceback (most recent call last):
  File "/tmp/datetimetest.py", line 6, in <module>
    np.issubdtype(dtype, np.number)
  File "/home/****/.cache/uv/archive-v0/pa2nJmRNwJrYZLooIE9pq/lib/python3.12/site-packages/numpy/_core/numerictypes.py", line 530, in issubdtype
    arg1 = dtype(arg1).type
           ^^^^^^^^^^^
TypeError: Cannot interpret 'datetime64[ns, UTC]' as a data type

Python and NumPy Versions:

Tested with the following combinations:

1.21.0
3.9.21 (main, Mar 17 2025, 21:01:54) 
1.21.5
3.9.21 (main, Mar 17 2025, 21:01:54) 

pandas 1.2.3, 1.2.4. 1.2.5, (current when #19187 was reported) and 2.2.3

1.22.0
3.10.12 (main, Feb  4 2025, 14:57:36) [GCC 11.4.0]
1.26.4
3.9.21 (main, Mar 17 2025, 21:01:54) 
2.0.2
3.12.8 (main, Jan 14 2025, 22:49:14) [Clang 19.1.6 ]
2.2.5
3.12.8 (main, Jan 14 2025, 22:49:14) [Clang 19.1.6 ]
2.2.5
3.13.2 (main, Mar 17 2025, 21:02:54) [Clang 20.1.0 ]

Runtime Environment:

[{'numpy_version': '2.2.5',
  'python': '3.13.2 (main, Mar 17 2025, 21:02:54) [Clang 20.1.0 ]',
  'uname': uname_result(system='Linux', node='RNG-C-003M3', release='6.8.0-59-generic', version='#61~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 15 17:03:15 UTC 2', machine='x86_64')},
 {'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
                      'found': ['SSSE3',
                                'SSE41',
                                'POPCNT',
                                'SSE42',
                                'AVX',
                                'F16C',
                                'FMA3',
                                'AVX2'],
                      'not_found': ['AVX512F',
                                    'AVX512CD',
                                    'AVX512_KNL',
                                    'AVX512_KNM',
                                    'AVX512_SKX',
                                    'AVX512_CLX',
                                    'AVX512_CNL',
                                    'AVX512_ICL']}},
 {'architecture': 'Haswell',
  'filepath': '/home/****/.cache/uv/archive-v0/7PdzZC8-2kfVkjeY8DQGF/lib/python3.13/site-packages/numpy.libs/libscipy_openblas64_-6bb31eeb.so',
  'internal_api': 'openblas',
  'num_threads': 20,
  'prefix': 'libscipy_openblas',
  'threading_layer': 'pthreads',
  'user_api': 'blas',
  'version': '0.3.28'}]

Context for the issue:

I am converting data and depending on if it's a numeric type or not (hence the use of np.issubdtype(..., np.number)) I need to treat the conversion differently.

I can of course work around it by checking beforehand if it's a datetime, but that would be kind of ugly and against any clean code principles.

@johannes-mueller johannes-mueller changed the title BUG: dtype datetime64[ns, UTC] not interpreted by issubtype BUG: dtype datetime64[ns, UTC] not interpreted by issubdtype May 12, 2025
@seberg
Copy link
Member

seberg commented May 15, 2025

This is a pandas dtype object, not NumPy one, so I suppose we could just return False if it errors (which is the same as you adding a try/except around np.dtype(dtype).
We may have a np.dtypes.NumericDType that can be used with isinstance() at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/numpy/numpy/issues/28946

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy