xarray.CFTimeIndex.take#

CFTimeIndex.take(indices, axis=0, allow_fill=<no_default>, fill_value=<no_default>, **kwargs)[source]#

Return a new Index of the values selected by the indices.

For internal compatibility with numpy arrays.

Parameters:
  • indices (array-like) – Indices to be taken.

  • axis ({0 or 'index'}, optional) – The axis over which to select values, always 0 or ‘index’.

  • allow_fill (bool, optional) – How to handle negative values in indices.

    • False: negative values in indices indicate positional indices from the right, matching numpy.take().

    • True: negative values in indices indicate missing values. -1 entries are set to fill_value (using the default NA value of the caller’s dtype if not supplied). Any other negative values raise a ValueError.

    • Not supplied: defaults to allow_fill=False unless fill_value is explicitly provided, in which case fill semantics apply (allow_fill=True).

  • fill_value (scalar, optional) – If fill semantics apply (see allow_fill), indices specified by -1 are filled with fill_value. Not specifying fill_value or passing fill_value=None will fill using the default NA value of the caller’s dtype. If the Index’s dtype cannot hold fill_value, the result is promoted to a common dtype (e.g. an integer Index + np.nan fill is cast to float, while an integer Index + a string fill is cast to object).

  • **kwargs – Required for compatibility with numpy.

Returns:

Index – An index formed of elements at the given indices. Will be the same type as self, except for RangeIndex.

See also

numpy.ndarray.take

Return an array formed from the elements of a at the given indices.

Examples

>>> idx = pd.Index(["a", "b", "c"])
>>> idx.take([2, 2, 1, 2])
Index(['c', 'c', 'b', 'c'], dtype='str')