Take elements from an array. Parameters ---------- indices : sequence of int or one-dimensional np.ndarray of int Indices to be taken. allow_fill : bool, default False How to handle negative values in `indices`. * False:
(
self,
indices: TakeIndexer,
*,
allow_fill: bool = False,
fill_value: Any = None,
)
| 1883 | # ------------------------------------------------------------------------ |
| 1884 | |
| 1885 | def take( |
| 1886 | self, |
| 1887 | indices: TakeIndexer, |
| 1888 | *, |
| 1889 | allow_fill: bool = False, |
| 1890 | fill_value: Any = None, |
| 1891 | ) -> Self: |
| 1892 | """ |
| 1893 | Take elements from an array. |
| 1894 | |
| 1895 | Parameters |
| 1896 | ---------- |
| 1897 | indices : sequence of int or one-dimensional np.ndarray of int |
| 1898 | Indices to be taken. |
| 1899 | allow_fill : bool, default False |
| 1900 | How to handle negative values in `indices`. |
| 1901 | |
| 1902 | * False: negative values in `indices` indicate positional indices |
| 1903 | from the right (the default). This is similar to |
| 1904 | :func:`numpy.take`. |
| 1905 | |
| 1906 | * True: negative values in `indices` indicate |
| 1907 | missing values. These values are set to `fill_value`. Any other |
| 1908 | other negative values raise a ``ValueError``. |
| 1909 | |
| 1910 | fill_value : any, optional |
| 1911 | Fill value to use for NA-indices when `allow_fill` is True. |
| 1912 | This may be ``None``, in which case the default NA value for |
| 1913 | the type, ``self.dtype.na_value``, is used. |
| 1914 | |
| 1915 | For many ExtensionArrays, there will be two representations of |
| 1916 | `fill_value`: a user-facing "boxed" scalar, and a low-level |
| 1917 | physical NA value. `fill_value` should be the user-facing version, |
| 1918 | and the implementation should handle translating that to the |
| 1919 | physical version for processing the take if necessary. |
| 1920 | |
| 1921 | Returns |
| 1922 | ------- |
| 1923 | ExtensionArray |
| 1924 | An array formed with selected `indices`. |
| 1925 | |
| 1926 | Raises |
| 1927 | ------ |
| 1928 | IndexError |
| 1929 | When the indices are out of bounds for the array. |
| 1930 | ValueError |
| 1931 | When `indices` contains negative values other than ``-1`` |
| 1932 | and `allow_fill` is True. |
| 1933 | |
| 1934 | See Also |
| 1935 | -------- |
| 1936 | numpy.take : Take elements from an array along an axis. |
| 1937 | api.extensions.take : Take elements from an array. |
| 1938 | |
| 1939 | Notes |
| 1940 | ----- |
| 1941 | ExtensionArray.take is called by ``Series.__getitem__``, ``.loc``, |
| 1942 | ``iloc``, when `indices` is a sequence of values. Additionally, |
no test coverage detected