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

cftime.num2date fails on an empty integer-dtype array #287

Closed
spencerkclark opened this issue Aug 6, 2022 · 0 comments
Closed

cftime.num2date fails on an empty integer-dtype array #287

spencerkclark opened this issue Aug 6, 2022 · 0 comments

Comments

@spencerkclark
Copy link
Collaborator

cftime.num2date behaves as expected when passing in an empty array of dtype float64:

>>> cftime.num2date(np.array([], dtype="float64"), "days since 1970-01-01", calendar="proleptic_gregorian", only_use_cftime_datetimes=True)
array([], dtype=object)

However it raises an error if the empty array has an integer dtype:

>>> cftime.num2date(np.array([], dtype="int64"), "days since 1970-01-01", calendar="proleptic_gregorian", only_use_cftime_datetimes=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "src/cftime/_cftime.pyx", line 604, in cftime._cftime.num2date
  File "src/cftime/_cftime.pyx", line 442, in cftime._cftime.scale_times
  File "<__array_function__ internals>", line 180, in amin
  File "/Users/spencer/Software/miniconda3/envs/xarray-tests-py38/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 2916, in amin
    return _wrapreduction(a, np.minimum, 'min', axis, None, out,
  File "/Users/spencer/Software/miniconda3/envs/xarray-tests-py38/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 86, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation minimum which has no identity

It would be good if both of these examples produced the same result.

cc: @dcherian
xref: pydata/xarray#6882

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

No branches or pull requests

2 participants