-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
DEP: Deprecate 'generic' unit in np.timedelta64 and np.datetime64 #29619
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
base: main
Are you sure you want to change the base?
DEP: Deprecate 'generic' unit in np.timedelta64 and np.datetime64 #29619
Conversation
pytest.ini
Outdated
@@ -27,6 +27,8 @@ filterwarnings = | |||
ignore:\n\n `numpy.distutils`:DeprecationWarning | |||
# Ignore DeprecationWarning from typing.mypy_plugin | |||
ignore:`numpy.typing.mypy_plugin` is deprecated:DeprecationWarning | |||
# Ignore Runtime Warning from datetime by calculating unitless value and unitful value | |||
ignore:Casting from unitless timedelta to unitful timedelta is ambiguous.:RuntimeWarning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that if we do this, we'd likely want at least one test case that actually makes sure that the warning is issued.
I see locally that there are 18 failures if this is removed though, and we wouldn't want 18 checks for the warning. Still, it might be nice if we could suppress most of them but enforce at least one of them.
That said, the discussion in the matching issue suggests that the decision here may be tricky, so it may be best to wait for some design feedback first before making changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the feedback!
I agree that adding a test case to check this warning makes sense.
As you suggested, I’ll wait for the design feedback before making the change.
Needs a release note. |
…4` to unitful one. This is a temporary solution to handle numpy#28287. Rasing `RuntimeWarning` encourages users to pay attention to the behavior.
7b3b00a
to
902f4ac
Compare
53036ac
to
93ae278
Compare
….datetime64` The ``generic`` unit in `numpy.timedelta64` and `numpy.datetime64` is now deprecated. Using it will raise a ``FutureWarning``. (See numpy#28287)
93ae278
to
9e14d71
Compare
np.timedelta64
to unitful one.
(Updated from previous PR description.)
This PR deprecates the
generic
unit innp.timedelta64
andnp.datetime64
. Using this unit can lead to unexpected behavior in some cases (see #28287 for details). Usinggeneric
unit now raises aFutureWarning
.Changes
Main
FutureWarning
whennp.timedelta64
ornp.datetime64
is constructed with thegeneric
unit.Test
Test updates fall into three categories.
Suppressing the warning in tests where the
generic
unit seems to be used intentionally. (@pytest.mark.filterwarning("ignore::FutureWarning"
)Adding tests to check
generic
unit's behavior. Some tests usesgeneric
timedelta inpytest.mark.parametrize
. In such cases, the warnings cannot be suppressed withpytest.mark.filterwarnings
. Instead, this PR add additional tests to check onlygeneric
unit's behavior.Modifying tests to use an explicit unit instead of
generic
.Future Work
These works are not included in this PR and I am planning to do them in future PRs. But, if you think they should be included in this PR, please let me know. I am happy to do so.
NaT
is allowed withgeneric
unit. We may want to disallow this in future.np.timedelta64()
creates ageneric
timedelta with value0
. We may want to change this to create a timedelta with an explicit unit (e.g.,np.timedelta64(0, 's')
) instead.np.ones_like
now raisesFutureWarning
when the input array is of timedelta type.1
value with specific unit.np.all_close
now raisesFutureWarning
when the input arrays are of datetime or timedelta type.atol
is not allowed to betimedelta64
because it is supposed to be printed withg
format. ("{atol:g}"
in the code.)