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
importnumpyasnpimportxarrayasxrimportcf_xarraylev=np.arange(1, 11)
lev=xr.DataArray(lev, dims='lev', attrs={'units': 'km', 'axis': 'Z'})
data=np.arange(lev.size)
data=xr.DataArray(data, dims='lev', coords={'lev': lev})
print(data.cf.axes) # prints {'Z': ['lev']}print(data[{'lev': 0}]) # prints data for level value "1"print(data.loc[{'lev': 1}]) # prints data for level value "1"
The cf accessor cannot handle dictionary-style position-based indexing:
>>>data.cf[{'Z': 0}]
File~/miniconda3/lib/python3.10/site-packages/cf_xarray/accessor.py:2402, inCFDataArrayAccessor.__getitem__(self, key)
2370""" 2371 Index into a DataArray making use of CF attributes. 2372 (...) 2398 Add additional keys by specifying "custom criteria". See :ref:`custom_criteria` for more. 2399 """2401ifnotisinstance(key, str):
->2402raiseKeyError(
2403f"Cannot use a list of keys with DataArrays. Expected a single string. Received {key!r} instead."2404 )
2406return_getitem(self, key)
KeyError: "Cannot use a list of keys with DataArrays. Expected a single string. Received {'Z': 0} instead."
It also cannot handle dictionary-style coordinate-based inexing:
>>>data.cf.loc[{'Z': 0}]
File~/miniconda3/lib/python3.10/site-packages/cf_xarray/accessor.py:576, in_getattr(obj, attr, accessor, key_mappers, wrap_classes, extra_decorator)
573func: Callable=attribute575else:
-->576raiseAttributeError(
577f"cf_xarray does not know how to wrap attribute '{type(obj).__name__}.{attr}'. "578"Please file an issue if you have a solution."579 )
581 @functools.wraps(func)
582defwrapper(*args, **kwargs):
583posargs, arguments=accessor._process_signature(
584func, args, kwargs, key_mappers585 )
AttributeError: cf_xarraydoesnotknowhowtowrapattribute'DataArray.loc'. Pleasefileanissueifyouhaveasolution.
I'd be interested in addressing this but don't currently have time. Thought I'd just get the issue on this project's radar for now (if it wasn't already / I didn't miss an already-open thread).
The text was updated successfully, but these errors were encountered:
Given the following sample data:
The cf accessor cannot handle dictionary-style position-based indexing:
It also cannot handle dictionary-style coordinate-based inexing:
I'd be interested in addressing this but don't currently have time. Thought I'd just get the issue on this project's radar for now (if it wasn't already / I didn't miss an already-open thread).
The text was updated successfully, but these errors were encountered: