Skip to content

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

@johannes-mueller

Description

@johannes-mueller

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy