@@ -463,45 +463,51 @@ def factorize(self, na_sentinel=-1):
463
463
# Indexing methods
464
464
# ------------------------------------------------------------------------
465
465
466
- def take (self , indexer , allow_fill = False , fill_value = None ):
466
+ def take (self , indices , allow_fill = False , fill_value = None ):
467
467
# type: (Sequence[int], bool, Optional[Any]) -> ExtensionArray
468
468
"""Take elements from an array.
469
469
470
470
Parameters
471
471
----------
472
- indexer : sequence of integers
472
+ indices : sequence of integers
473
473
Indices to be taken. See Notes for how negative indicies
474
474
are handled.
475
475
allow_fill : bool, default False
476
- How to handle negative values in `indexer `.
476
+ How to handle negative values in `indices `.
477
477
478
- For False values (the default), negative values in `indexer `
478
+ For False values (the default), negative values in `indices `
479
479
indiciate slices from the right.
480
480
481
- For True values, indicies where `indexer ` is ``-1`` indicate
481
+ For True values, indicies where `indices ` is ``-1`` indicate
482
482
missing values. These values are set to `fill_value`. Any other
483
483
other negative value should raise a ``ValueError``.
484
484
fill_value : any, optional
485
485
Fill value to use for NA-indicies when `allow_fill` is True.
486
486
This may be ``None``, in which case the default NA value for
487
487
the type, ``self.dtype.na_value``, is used.
488
488
489
+ For many ExtensionArrays, there will be two representations of
490
+ `fill_value`: a user-facing "boxed" scalar, and a low-level
491
+ physical NA value. `fill_value` should be the user-facing version,
492
+ and the implementation should handle translating that to the
493
+ physical version for processing the take if nescessary.
494
+
489
495
Returns
490
496
-------
491
497
ExtensionArray
492
498
493
499
Raises
494
500
------
495
501
IndexError
496
- When the indexer is out of bounds for the array.
502
+ When the indices are out of bounds for the array.
497
503
ValueError
498
- When the indexer contains negative values other than ``-1``
504
+ When `indices` contains negative values other than ``-1``
499
505
and `allow_fill` is True.
500
506
501
507
Notes
502
508
-----
503
509
ExtensionArray.take is called by ``Series.__getitem__``, ``.loc``,
504
- ``iloc``, when the indexer is a sequence of values. Additionally,
510
+ ``iloc``, when `indices` is a sequence of values. Additionally,
505
511
it's called by :meth:`Series.reindex`, or any other method
506
512
that causes realignemnt, with a `fill_value`.
507
513
@@ -518,14 +524,17 @@ def take(self, indexer, allow_fill=False, fill_value=None):
518
524
519
525
.. code-block:: python
520
526
521
- def take(self, indexer , allow_fill=False, fill_value=None):
527
+ def take(self, indices , allow_fill=False, fill_value=None):
522
528
from pandas.core.algorithms import take
523
529
530
+ # If the ExtensionArray is backed by an ndarray, then
531
+ # just pass that here instead of coercing to object.
524
532
data = self.astype(object)
533
+
525
534
if allow_fill and fill_value is None:
526
535
fill_value = self.dtype.na_value
527
536
528
- result = take(data, indexer , fill_value=fill_value,
537
+ result = take(data, indices , fill_value=fill_value,
529
538
allow_fill=allow_fill)
530
539
return self._from_sequence(result)
531
540
"""
0 commit comments