home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 217216935

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
217216935 MDU6SXNzdWUyMTcyMTY5MzU= 1329 Cannot open NetCDF file if dimension with time coordinate has length 0 (`ValueError` when decoding CF datetime) 500246 closed 0     7 2017-03-27T11:33:07Z 2022-08-10T17:25:20Z 2022-08-10T17:25:20Z CONTRIBUTOR      

If a data set has a zero-sized coordinate that is a time index, reading fails. A ValueError is triggered when xarray tries to decode the array, as shown below:

``` $ cat mwe.py

!/usr/bin/env python

import numpy import xarray

ds = xarray.Dataset( {"a": ("x", [])}, coords={"x": numpy.zeros(shape=0, dtype="M8[ns]")})

ds.to_netcdf("/tmp/test.nc")

xarray.open_dataset("/tmp/test.nc") $ ./mwe.py Traceback (most recent call last): File "./mwe.py", line 12, in <module> xarray.open_dataset("/tmp/test.nc") File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/backends/api.py", line 302, in open_dataset return maybe_decode_store(store, lock) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/backends/api.py", line 223, in maybe_decode_store drop_variables=drop_variables) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/conventions.py", line 952, in decode_cf ds = Dataset(vars, attrs=attrs) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/dataset.py", line 358, in init self._set_init_vars_and_dims(data_vars, coords, compat) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/dataset.py", line 373, in _set_init_vars_and_dims data_vars, coords, compat=compat) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/merge.py", line 365, in merge_data_and_coords return merge_core(objs, compat, join, explicit_coords=explicit_coords) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/merge.py", line 413, in merge_core expanded = expand_variable_dicts(aligned) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/merge.py", line 213, in expand_variable_dicts var = as_variable(var, name=name) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/variable.py", line 83, in as_variable obj = obj.to_index_variable() File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/variable.py", line 322, in to_index_variable encoding=self._encoding, fastpath=True) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/variable.py", line 1173, in init self._data = PandasIndexAdapter(self._data) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/indexing.py", line 497, in init self.array = utils.safe_cast_to_index(array) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/utils.py", line 57, in safe_cast_to_index index = pd.Index(np.asarray(array), **kwargs) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/numpy/core/numeric.py", line 531, in asarray return array(a, dtype, copy=False, order=order) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/indexing.py", line 373, in array return np.asarray(array[self.key], dtype=None) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/conventions.py", line 408, in getitem calendar=self.calendar) File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/conventions.py", line 151, in decode_cf_datetime pd.to_timedelta(flat_num_dates.min(), delta) + ref_date File "/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/numpy/core/_methods.py", line 29, in _amin return umr_minimum(a, axis, None, out, keepdims) ValueError: zero-size array to reduction operation minimum which has no identity $ ncdump /tmp/test.nc netcdf test { dimensions: x = UNLIMITED ; // (0 currently) variables: double a(x) ; a:_FillValue = NaN ; int64 x(x) ; x:units = "days since 1970-01-01 00:00:00" ; x:calendar = "proleptic_gregorian" ;

// global attributes: :_NCProperties = "version=1|netcdflibversion=4.4.1|hdf5libversion=1.8.18" ; data: } ```

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1329/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 7 rows from issue in issue_comments
Powered by Datasette · Queries took 0.813ms · About: xarray-datasette