You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting invalid units for time axis encoding results in an exception AttributeError: 'NoneType' object has no attribute 'groups'
What you expected to happen:
It should say "invalid time units", like this (see commented out line below) ValueError: invalid time units: days after 1/3/2000
Minimal Complete Verifiable Example:
# Put your MCVE code hereimportpandasaspdimportxarrayasxrds=xr.Dataset(data_vars={'v': (('t',), [0,])},
coords={'t': [pd.Timestamp(2000, 1, 1)]})
ds.t.encoding['units'] ='days since Big Bang'#ds.t.encoding['units'] = 'days after 1/3/2000'ds.to_netcdf('/tmp/x.nc', mode='w')
---------------------------------------------------------------------------AttributeErrorTraceback (mostrecentcalllast)
<ipython-input-16-0d97a797be64>in<module>5ds.t.encoding['units'] ='days since Big Bang'6#ds.t.encoding['units'] = 'days after 1/3/2000'---->7ds.to_netcdf('/tmp/x.nc', mode='w')
~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/core/dataset.pyinto_netcdf(self, path, mode, format, group, engine, encoding, unlimited_dims, compute, invalid_netcdf)
1752from ..backends.apiimportto_netcdf1753->1754returnto_netcdf(
1755self,
1756path,
~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/backends/api.pyinto_netcdf(dataset, path_or_file, mode, format, group, engine, encoding, unlimited_dims, compute, multifile, invalid_netcdf)
1066# TODO: allow this work (setting up the file for writing array data)1067# to be parallelized with dask->1068dump_to_store(
1069dataset, store, writer, encoding=encoding, unlimited_dims=unlimited_dims1070 )
~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/backends/api.pyindump_to_store(dataset, store, writer, encoder, encoding, unlimited_dims)
1113variables, attrs=encoder(variables, attrs)
1114->1115store.store(variables, attrs, check_encoding, writer, unlimited_dims=unlimited_dims)
11161117~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/backends/common.pyinstore(self, variables, attributes, check_encoding_set, writer, unlimited_dims)
261writer=ArrayWriter()
262-->263variables, attributes=self.encode(variables, attributes)
264265self.set_attributes(attributes)
~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/backends/common.pyinencode(self, variables, attributes)
350# All NetCDF files get CF encoded by default, without this attempting351# to write times, for example, would fail.-->352variables, attributes=cf_encoder(variables, attributes)
353variables= {k: self.encode_variable(v) fork, vinvariables.items()}
354attributes= {k: self.encode_attribute(v) fork, vinattributes.items()}
~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/conventions.pyincf_encoder(variables, attributes)
841_update_bounds_encoding(variables)
842-->843new_vars= {k: encode_cf_variable(v, name=k) fork, vinvariables.items()}
844845# Remove attrs from bounds variables (issue #2921)~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/conventions.pyin<dictcomp>(.0)
841_update_bounds_encoding(variables)
842-->843new_vars= {k: encode_cf_variable(v, name=k) fork, vinvariables.items()}
844845# Remove attrs from bounds variables (issue #2921)~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/conventions.pyinencode_cf_variable(var, needs_copy, name)
267variables.UnsignedIntegerCoder(),
268 ]:
-->269var=coder.encode(var, name=name)
270271# TODO(shoyer): convert all of these to use coders, too:~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/coding/times.pyinencode(self, variable, name)
510variable511 ):
-->512 (data, units, calendar) =encode_cf_datetime(
513data, encoding.pop("units", None), encoding.pop("calendar", None)
514 )
~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/coding/times.pyinencode_cf_datetime(dates, units, calendar)
448units=infer_datetime_units(dates)
449else:
-->450units=_cleanup_netcdf_time_units(units)
451452ifcalendarisNone:
~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/coding/times.pyin_cleanup_netcdf_time_units(units)
399400def_cleanup_netcdf_time_units(units):
-->401delta, ref_date=_unpack_netcdf_time_units(units)
402try:
403units="{} since {}".format(delta, format_timestamp(ref_date))
~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/coding/times.pyin_unpack_netcdf_time_units(units)
130131delta_units, ref_date= [s.strip() forsinmatches.groups()]
-->132ref_date=_ensure_padded_year(ref_date)
133134returndelta_units, ref_date~/miniconda3/envs/xarray/lib/python3.9/site-packages/xarray-0.0.0-py3.9.egg/xarray/coding/times.pyin_ensure_padded_year(ref_date)
105# appropriately106matches_start_digits=re.match(r"(\d+)(.*)", ref_date)
-->107ref_year, everything_else= [sforsinmatches_start_digits.groups()]
108ref_date_padded="{:04d}{}".format(int(ref_year), everything_else)
109AttributeError: 'NoneType'objecthasnoattribute'groups'
Anything else we need to know?:
Are there detail specifications for the valid units string? Setting it to 1/3/2000 surprised me (my locale: LANG=en_CA.UTF-8). Environment:
Latest code from github: xarray version 0.0.0
Output of xr.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:46)
[GCC 9.3.0]
python-bits: 64
OS: Linux
OS-release: 5.10.11-200.fc33.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_CA.UTF-8
LOCALE: en_CA.UTF-8
libhdf5: 1.10.6
libnetcdf: 4.8.0
What happened:
Setting invalid units for time axis encoding results in an exception
AttributeError: 'NoneType' object has no attribute 'groups'
What you expected to happen:
It should say "invalid time units", like this (see commented out line below)
ValueError: invalid time units: days after 1/3/2000
Minimal Complete Verifiable Example:
Anything else we need to know?:
Are there detail specifications for the valid units string? Setting it to 1/3/2000 surprised me (my locale: LANG=en_CA.UTF-8).
Environment:
Latest code from github: xarray version 0.0.0
Output of xr.show_versions()
INSTALLED VERSIONS ------------------ commit: None python: 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:46) [GCC 9.3.0] python-bits: 64 OS: Linux OS-release: 5.10.11-200.fc33.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_CA.UTF-8 LOCALE: en_CA.UTF-8 libhdf5: 1.10.6 libnetcdf: 4.8.0xarray: 0.0.0
pandas: 1.2.4
numpy: 1.20.2
scipy: None
netCDF4: 1.5.6
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: 2.7.1
cftime: 1.4.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2021.04.0
distributed: 2021.04.0
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
pint: None
setuptools: 49.6.0.post20210108
pip: 21.0.1
conda: None
pytest: None
IPython: 7.22.0
sphinx: None
The text was updated successfully, but these errors were encountered: