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

Allow converting NumPy datetimes to int #8024

Merged
merged 3 commits into from
Mar 9, 2023
Merged

Allow converting NumPy datetimes to int #8024

merged 3 commits into from
Mar 9, 2023

Conversation

apmasell
Copy link
Contributor

@apmasell apmasell commented May 4, 2022

Add support for int(numpy.datetime64) and int(numpy.timedelta64).

@stuartarchibald
Copy link
Contributor

Thanks for the patch @apmasell, I think that converting datetime64/timedelta64 to int is not permitted unless the unit is 'ns', whereas I think the .view() method should work all the time (to e.g. .view(np.int64)).

@sklam
Copy link
Member

sklam commented May 9, 2022

int(timedelta64) has different rules for the units than int(datetime64):

In [3]: td = np.timedelta64(1, 'Y')

In [4]: td
Out[4]: numpy.timedelta64(1,'Y')

In [5]: int(td)
Out[5]: 1

We'll need to check what numpy is doing to be sure.

numba/core/typing/builtins.py Outdated Show resolved Hide resolved
Comment on lines 566 to 598
with self.assertRaises((TypeError, TypingError)):
f(DT('2014'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test when TypingError is raised that the expected message is shown?

@sklam sklam added 4 - Waiting on author Waiting for author to respond to review and removed 3 - Ready for Review labels Jun 1, 2022
apmasell and others added 3 commits June 2, 2022 15:36
Add support for `int(numpy.datetime64)` and `int(numpy.timedelta64)`.
As titled.

Co-authored-by: Siu Kwan Lam <1929845+sklam@users.noreply.github.com>
Ensure the type conversion errors includes the desired message
@apmasell apmasell added 3 - Ready for Review and removed 4 - Waiting on author Waiting for author to respond to review labels Jun 2, 2022
@sklam sklam self-assigned this Jul 12, 2022
@sklam sklam added this to the Numba 0.57 RC milestone Jul 12, 2022
Copy link
Member

@sklam sklam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in review. Patch looks good.

@sklam sklam added 5 - Ready to merge Review and testing done, is ready to merge and removed 3 - Ready for Review labels Mar 9, 2023
@sklam sklam merged commit c4424fb into numba:main Mar 9, 2023
@apmasell apmasell deleted the datetime_conversion branch March 10, 2023 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge Review and testing done, is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants