Skip to content

BUG: Raise warning for integer arithmetic with timedelta64/datetime64 arrays#31290

Open
may12day wants to merge 3 commits intonumpy:mainfrom
may12day:timedelta64-associativity
Open

BUG: Raise warning for integer arithmetic with timedelta64/datetime64 arrays#31290
may12day wants to merge 3 commits intonumpy:mainfrom
may12day:timedelta64-associativity

Conversation

@may12day
Copy link
Copy Markdown

@may12day may12day commented Apr 20, 2026

PR summary

Adds deprecation warning for arithmetic between integer arrays and timedelta64 arrays.
Same issue was found in datetime64, added deprecation there too. Happy to revert if out of scope.
Relates to #31255

First time committer introduction

Hi, was going through internals of numpy and saw the issue. Wanted to contribute and I'll be happy to receive feedback.

AI Disclosure

Took minimal help from Claude in writing test cases.

@may12day may12day force-pushed the timedelta64-associativity branch from e3ced45 to 159d053 Compare April 21, 2026 14:05
@may12day may12day changed the title Raise warning for integer arithmetic with timedelta64/datetime64 arrays BUG: Raise warning for integer arithmetic with timedelta64/datetime64 arrays Apr 21, 2026
@ngoldbaum
Copy link
Copy Markdown
Member

Please run the test suite and make sure it passes locally. Feel free to turn on CI for your fork if you want to have it run without us pressing any approval buttons.

Ping @riku-sakamoto in case you want to take a look.

Comment thread numpy/_core/tests/test_deprecations.py Outdated

class TestDeprecatedIntegerTimedeltaArrayArithmetic(_DeprecationTestCase):
# Deprecation in NumPy 2.5, 2026-04
message = "The 'generic' unit for NumPy timedelta is deprecated"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems that it might be more consistent to add test methods into TestDeprecatedGenericTimedelta since the same deprecation message is raised.

Comment thread numpy/_core/tests/test_deprecations.py Outdated
Comment on lines +460 to +461
if op == np.add:
self.assert_deprecated(op, num=None, args=(int_arr, timedelta_arr))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we need to test both add and subtract operations. It doesn't seem that this if statement is necessary.

@may12day may12day force-pushed the timedelta64-associativity branch from c1acec4 to 956b6bc Compare April 23, 2026 19:34
@may12day
Copy link
Copy Markdown
Author

Hi @ngoldbaum
Whenever you have a second, could you approve the workflows to run?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants