Skip to content
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

Handle np.datetime64 and other numpy dtypes with odd subclasses/constructors #47

Merged
merged 4 commits into from
Mar 11, 2025

Conversation

sneakers-the-rat
Copy link
Collaborator

Fix: #46

np.datetime64 isn't a dtype class like other dtypes, it produces a different type:

>>> arr = np.array([np.datetime64(datetime.now())], dtype=np.datetime64)
>>> arr.dtype
dtype('<M8[us]')
>>> type(arr.dtype)
numpy.dtypes.DateTime64DType

But the type attribute is unambiguous:

>>> arr.dtype.type
numpy.datetime64

This is similar to numpy string dtypes.

Fix is simple and generic - just check the type attribute if it's present.

opening first with failing test, then with fix

@sneakers-the-rat sneakers-the-rat added bug Something isn't working dtype labels Mar 11, 2025
@coveralls
Copy link

coveralls commented Mar 11, 2025

Pull Request Test Coverage Report for Build 13777381869

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 98.302%

Totals Coverage Status
Change from base Build 12941001383: 0.0%
Covered Lines: 1505
Relevant Lines: 1531

💛 - Coveralls

@sneakers-the-rat sneakers-the-rat merged commit f3e7e06 into main Mar 11, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

raise Validatation Error on numpy.datetime64 type checking
2 participants