Skip to content

np.timedelta64 should not be an subclass of np.integer #10685

@shoyer

Description

@shoyer

This is particularly inconsistent because this isn't the case for datetime64:

In [12]: issubclass(np.timedelta64, np.integer)
Out[12]: True

In [13]: issubclass(np.datetime64, np.integer)
Out[13]: False

Looking at the subclass hierarchy, we observe:

In [15]: np.datetime64.mro()
Out[15]: [numpy.datetime64, numpy.generic, object]

In [16]: np.timedelta64.mro()
Out[16]:
[numpy.timedelta64,
 numpy.signedinteger,
 numpy.integer,
 numpy.number,
 numpy.generic,
 object]

I would suggest that we make np.timedelta64 also inherit directly from np.generic.

I'm sure there was a reason for this originally, but in my experience this sort of sloppiness around type casting leads to bugs and confusion (e.g., see pydata/xarray#1952).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions