-
-
Notifications
You must be signed in to change notification settings - Fork 8
✅ Add type tests covering all relevant datetime64 and timedelta64
#859
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3ea22c9
add type tests covering all relevant datetime64 and timedelta64
Aniketsy f7453fe
tests: ignore assert_type errors
Aniketsy 04b68e7
add comment for type ignores
Aniketsy cca2596
Update src/numpy-stubs/@test/static/accept/temporal_scalar_ops.pyi
Aniketsy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/numpy-stubs/@test/static/accept/temporal_scalar_ops.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Type tests for datetime64/timedelta64 operations using representative subtype cases | ||
|
|
||
| import datetime as dt | ||
| from typing import assert_type | ||
|
|
||
| import numpy as np | ||
|
|
||
| DT = np.datetime64 | ||
| TD = np.timedelta64 | ||
|
|
||
| dt_default: DT | ||
| dt_none: DT[None] | ||
| dt_int: DT[int] | ||
| dt_datetime: DT[dt.datetime] | ||
| dt_date: DT[dt.date] | ||
|
|
||
| td_default: TD | ||
| td_none: TD[None] | ||
| td_int: TD[int] | ||
| td_timedelta: TD[dt.timedelta] | ||
|
|
||
| assert_type(dt_default + td_default, DT) | ||
| assert_type(dt_default + td_none, DT[None]) | ||
| # mypy produces datetime64[Any] instead of datetime64[None] for datetime64[None] operands. | ||
| assert_type(dt_none + td_default, DT[None]) # type: ignore[assert-type] | ||
| assert_type(dt_int + td_int, DT[int]) | ||
| assert_type(dt_datetime + td_timedelta, DT[dt.datetime]) | ||
| assert_type(dt_date + td_timedelta, DT[dt.date]) | ||
|
|
||
| assert_type(dt_default - td_default, DT) | ||
| assert_type(dt_default - td_none, DT[None]) | ||
| assert_type(dt_none - td_default, DT[None]) # type: ignore[assert-type] | ||
| assert_type(dt_int - td_int, DT[int]) | ||
| assert_type(dt_datetime - td_timedelta, DT[dt.datetime]) | ||
| assert_type(dt_date - td_timedelta, DT[dt.date]) | ||
| assert_type(dt_date - td_int, DT[dt.date | int]) | ||
|
|
||
| assert_type(dt_default - dt_default, TD) | ||
| assert_type(dt_none - dt_default, TD[None]) # type: ignore[assert-type] | ||
| assert_type(dt_int - dt_int, TD[int]) | ||
| assert_type(dt_datetime - dt_datetime, TD[dt.timedelta]) | ||
| assert_type(dt_date - dt_date, TD[dt.timedelta]) | ||
|
|
||
| assert_type(td_default + td_default, TD) | ||
| assert_type(td_none + td_default, TD[None]) # type: ignore[assert-type] | ||
| assert_type(td_int + td_int, TD[int]) | ||
| assert_type(td_timedelta + td_timedelta, TD[dt.timedelta]) | ||
|
|
||
| assert_type(td_default - td_default, TD) | ||
| assert_type(td_none - td_default, TD[None]) # type: ignore[assert-type] | ||
| assert_type(td_int - td_int, TD[int]) | ||
| assert_type(td_timedelta - td_timedelta, TD[dt.timedelta]) | ||
|
|
||
| assert_type(td_default / td_default, np.float64) | ||
| assert_type(td_none / td_default, np.float64) | ||
|
|
||
| assert_type(td_default % td_default, TD) | ||
| assert_type(td_none % td_default, TD[None]) # type: ignore[assert-type] | ||
|
|
||
| assert_type(td_default * 0, TD) | ||
| assert_type(td_none * 0, TD[None]) | ||
| assert_type(td_int * 0, TD[int]) | ||
| assert_type(td_timedelta * 0, TD[dt.timedelta]) | ||
|
|
||
| assert_type(0 * td_default, TD) | ||
| assert_type(0 * td_none, TD[None]) | ||
| assert_type(0 * td_int, TD[int]) | ||
| assert_type(0 * td_timedelta, TD[dt.timedelta]) | ||
|
|
||
| assert_type(td_default / 0, TD) | ||
| assert_type(td_none / 0, TD[None]) | ||
| assert_type(td_int / 0, TD[int]) | ||
| assert_type(td_timedelta / 0, TD[dt.timedelta]) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.