encode_attrs

Contents

encode_attrs#

eoio.serialisation.attrs.encode_attrs(obj: T, *, dict_style: str = 'dot', strict: bool = False, inplace: bool = False) → T[source]#

Convert attributes to values that can be written to netCDF or Zarr.

Applies to dataset-level, variable and coordinate attributes, and to every node of a DataTree. An eoio:attr_encoding marker is added to each scope that needed encoding, so decode_attrs() can reverse it exactly.

Parameters:
  • obj – Dataset, DataArray or DataTree whose attributes should be encoded.

  • dict_style – "dot" to dot-flatten nested dicts, or "json" to encode each as a single JSON blob.

  • strict – If True, raise on a value no codec handles. If False, fall back to str() with a warning.

  • inplace – Whether to modify obj rather than a copy.

Returns:

The object with encoded attributes.

Raises:
  • ValueError – If dict_style is not "dot" or "json".

  • TypeError – If strict is set and a value cannot be encoded.