Skip to content

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

Closed
@hmaarrfk

Description

@hmaarrfk

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions