ExtensionArray.take(self, indices: Sequence[int], allow_fill: bool = False, fill_value: Any = None) → pandas.core.dtypes.generic.ABCExtensionArray
[source]
Take elements from an array.
Parameters: |
|
---|---|
Returns: |
|
Raises: |
|
See also
numpy.take
api.extensions.take
ExtensionArray.take is called by Series.__getitem__
, .loc
, iloc
, when indices
is a sequence of values. Additionally, it’s called by Series.reindex()
, or any other method that causes realignment, with a fill_value
.
Here’s an example implementation, which relies on casting the extension array to object dtype. This uses the helper method pandas.api.extensions.take()
.
def take(self, indices, allow_fill=False, fill_value=None): from pandas.core.algorithms import take # If the ExtensionArray is backed by an ndarray, then # just pass that here instead of coercing to object. data = self.astype(object) if allow_fill and fill_value is None: fill_value = self.dtype.na_value # fill value should always be translated from the scalar # type for the array, to the physical storage type for # the data, before passing to take. result = take(data, indices, fill_value=fill_value, allow_fill=allow_fill) return self._from_sequence(result, dtype=self.dtype)
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.api.extensions.ExtensionArray.take.html