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

The new NON_NANOSECOND_WARNING is not very nice to end users #7237

Closed
hmaarrfk opened this issue Oct 30, 2022 · 5 comments · Fixed by #7238
Closed

The new NON_NANOSECOND_WARNING is not very nice to end users #7237

hmaarrfk opened this issue Oct 30, 2022 · 5 comments · Fixed by #7238

Comments

@hmaarrfk
Copy link
Contributor

What is your issue?

The new nanosecond warning doesn't really point anybody to where they should change their code.

Nor does it really tell them how to fix it.

import xarray as xr
import numpy as np
xr.DataArray(np.zeros(1, dtype='datetime64[us]'))

yields

xarray/core/variable.py:194: UserWarning: Converting non-nanosecond precision datetime values to nanosecond precision. This behavior can eventually be relaxed in xarray, as it is an artifact from pandas which is now beginning to support non-nanosecond precision values.

warnings.warn(NON_NANOSECOND_WARNING.format(case="datetime"))

I think at the very least, the stacklevel should be specified when calling the warn function.

It isn't really pretty, but I've been passing a parameter when I expect to pass up a warning to the end user:
eg. vispy/vispy#2405

However, others have not liked that approach.

@hmaarrfk hmaarrfk added the needs triage Issue that has not been reviewed by xarray team member label Oct 30, 2022
@headtr1ck headtr1ck added topic-error reporting and removed needs triage Issue that has not been reviewed by xarray team member labels Oct 30, 2022
@djhoese
Copy link
Contributor

djhoese commented May 8, 2023

Sorry for dragging this issue up again, but even with the new warning message I still have some questions. Do I have to switch to nanosecond precision times or will xarray/pandas/numpy just figure it out when I combine/compare times with different precisions?

@spencerkclark
Copy link
Member

For the time being xarray should behave as it always has, converting any non-nanosecond precision times to nanosecond-precision before being used internally.

@djhoese
Copy link
Contributor

djhoese commented May 8, 2023

And with new pandas (which I understand as being the thing/library that is changing) and new xarray, what will happen? What happens between nano and non-nano times?

@spencerkclark
Copy link
Member

Xarray will convert any non-nanosecond precision times to nanosecond precision (or an error will be raised if this is not possible).

@spencerkclark
Copy link
Member

For a little more discussion of this issue see #7493. As the example at the top of the issue notes, there is at least one place where non-nanosecond times can slip in (this is not intentional), but for most code pathways xarray should currently convert things automatically.

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

Successfully merging a pull request may close this issue.

4 participants