assign_attrs

UnitsAwareDataArray.assign_attrs(*args: Any, **kwargs: Any) Self

Assign new attrs to this object.

Returns a new object equivalent to self.attrs.update(*args, **kwargs).

Parameters:
  • *args – positional arguments passed into attrs.update.

  • **kwargs – keyword arguments passed into attrs.update.

Examples

>>> dataset = xr.Dataset({"temperature": [25, 30, 27]})
>>> dataset
<xarray.Dataset> Size: 24B
Dimensions:      (temperature: 3)
Coordinates:
  * temperature  (temperature) int64 24B 25 30 27
Data variables:
    *empty*
>>> new_dataset = dataset.assign_attrs(
...     units="Celsius", description="Temperature data"
... )
>>> new_dataset
<xarray.Dataset> Size: 24B
Dimensions:      (temperature: 3)
Coordinates:
  * temperature  (temperature) int64 24B 25 30 27
Data variables:
    *empty*
.. attribute:: units

Celsius

description

Temperature data

# Attributes of the new dataset

>>> new_dataset.attrs
{'units': 'Celsius', 'description': 'Temperature data'}
Returns:

assigned – A new object with the new attrs in addition to the existing data.

Return type:

same type as caller

See also

Dataset.assign