- 
                Notifications
    You must be signed in to change notification settings 
- Fork 35
Closed
Milestone
Description
Currently NetCDFTimeConverter.convert promotes scalar CalendarDateTime or cftime.datetime objects to arrays of floats:
>>> import cftime
>>> from nc_time_axis import NetCDFTimeConverter
>>> NetCDFTimeConverter.convert(cftime.DatetimeNoLeap(2010, 1, 1), None, None)
array([3650.])Within matplotlib, this can lead to unusual assignment behavior, which will eventually be deprecated in NumPy (numpy/numpy#16943):
$ python -Wd
>>> import cftime
>>> import matplotlib.pyplot as plt
>>> import nc_time_axis
>>> times = [cftime.DatetimeNoLeap(2000, 1, 1), cftime.DatetimeNoLeap(2000, 1, 2), cftime.DatetimeNoLeap(2000, 1, 3)]
>>> data = range(3)
>>> plt.plot(times, data)
.../matplotlib/transforms.py:943: DeprecationWarning: setting an array element with a sequence. This was supported in some cases where the elements are arrays with a single element. For example `np.array([1, np.array([2])], dtype=int)`. In the future this will raise the same ValueError as `np.array([1, [2]], dtype=int)`.
  self._points[:, 0] = interval
.../nc_time_axis/__init__.py:266: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. Use `object` by itself, which is identical in behavior, to silence this warning. If you specifically wanted the numpy scalar type, use `np.object_` here.
  if value.dtype != np.object:
[<matplotlib.lines.Line2D object at 0x7fc550278c40>]In the above example, self._points is np.array([[0., 0.], [1., 1.]]) and interval is (np.array([0.]), np.array([3650.])).  If the converter handled scalars without promoting them to arrays, interval would be (0., 3650.), and the assignment would proceed without warning.
xref: pydata/xarray#4265