larch.Dataset.dc.set_altids#

Dataset.dc.set_altids(altids, dim_name=None, dtype=None, inplace=False) Dataset#

Set the alternative ids for this Dataset.

Parameters:
  • altids (array-like of int) – Integer id codes.

  • dim_name (str, optional) – Use this dimension name for alternatives.

  • dtype (dtype, optional) – Coerce the altids to be this dtype.

  • inplace (bool, default False) – When true, apply the transformation in-place on the Dataset, otherwise return a modified copy.

Returns:

xarray.Dataset – The modified Dataset.

Examples

>>> import numpy as np
>>> from larch.dataset import Dataset
>>> ds = Dataset()
>>> ds = ds.dc.set_altids([1,2,3,4], dtype=np.int64)
>>> ds.dc.altids()
Int64Index([1, 2, 3, 4], dtype='int64', name='_altid_')
>>> ds.dc.n_alts
4
>>> ds2 = ds.dc.set_altids([7,8,9], dim_name='A', dtype=np.int64)
>>> ds2.dc.ALTID
'A'
>>> ds2.dc.altids()
Int64Index([7, 8, 9], dtype='int64', name='A')
>>> ds2
<xarray.Dataset>
Dimensions:  (_altid_: 4, A: 3)
Coordinates:
  * _altid_  (_altid_) int64 1 2 3 4
  * A        (A) int64 7 8 9
Data variables:
    *empty*
.. attribute:: _altid_

A