-
Notifications
You must be signed in to change notification settings - Fork 14
Closed
Description
Trying to quantify a DataArray
describing a dimension after pulling it out fails:
In [2]: ds = xr.Dataset(coords={"x": ("x", [0, 1], {"units": "m"}), "y": ("y", [5, 6, 7], {"units": "m"})})
...: ds
Out[2]:
<xarray.Dataset>
Dimensions: (x: 2, y: 3)
Coordinates:
* x (x) int64 0 1
* y (y) int64 5 6 7
Data variables:
*empty*
In [3]: q = ds.pint.quantify()
...: q
Out[3]:
<xarray.Dataset>
Dimensions: (x: 2, y: 3)
Coordinates:
* x (x) int64 0 1
* y (y) int64 5 6 7
Data variables:
*empty*
In [4]: q.x
Out[4]:
<xarray.DataArray 'x' (x: 2)>
array([0, 1])
Coordinates:
* x (x) int64 0 1
Attributes:
units: meter
In [5]: q.x.pint.quantify()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-ac870069d90f> in <module>
----> 1 q.x.pint.quantify()
.../pint_xarray/accessors.py in quantify(self, units, unit_registry, **unit_kwargs)
317 units = either_dict_or_kwargs(units, unit_kwargs, "quantify")
318
--> 319 registry = get_registry(unit_registry, units, conversion.extract_units(self.da))
320
321 unit_attrs = conversion.extract_unit_attributes(self.da)
.../pint_xarray/conversion.py in extract_units(obj)
248 name = obj.name if obj.name is not None else "<this-array>"
249
--> 250 ds = obj.rename(name).to_dataset()
251
252 units = extract_units(ds)
.../xarray/core/dataarray.py in to_dataset(self, dim, name, promote_attrs)
576 result = self._to_dataset_split(dim)
577 else:
--> 578 result = self._to_dataset_whole(name)
579
580 if promote_attrs:
.../xarray/core/dataarray.py in _to_dataset_whole(self, name, shallow_copy)
525 )
526 if name in self.coords:
--> 527 raise ValueError(
528 "cannot create a Dataset from a DataArray with "
529 "the same name as one of its coordinates"
ValueError: cannot create a Dataset from a DataArray with the same name as one of its coordinates
We should try to fix this.
Metadata
Metadata
Assignees
Labels
No labels