-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
As an example I have a DataArray called "my_dataarray" that looks something like this:
<xarray.DataArray 'values' (Type: 3)>
array([1, 2, 3])
Coordinates:
* Type (Type) object 'Type 1' 'Type 2' 'Type 3'
'Type' is a dimension on my DataArray. Note that 'Type' is also a DataArray that looks like this:
OrderedDict([('Type', <xarray.IndexVariable 'Type' (Type: 3)>
array(['Type 1', 'Type 2', 'Type 3'],
dtype='object'))])
Let's say I run:
'Type 1' in my_dataarray.Type
The result is False, even though 'Type 1' is in the "Type" dimension.
To get the result I was expecting I need to run:
'Type 1' in my_dataarray.Type.values
Stepping through the code, the problematic line is here:
xarray/xarray/core/dataarray.py
Line 487 in 20ec324
| return key in self._coords |
The test used for __contains__(self, key) on the Type dimension is whether the key is in the _coords of Type.
This is probably the right thing to do when the DataArray is used for storing data, but probably not what we want if the DataArray is being used as a dimension - it should instead check if 'Type 1' is in the values of Type?