Skip to content

Commit 05d8844

Browse files
committed
Updated docs
1 parent 31cd304 commit 05d8844

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

pandas/core/arrays/base.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -485,16 +485,18 @@ def take(self, indexer, fill_value=None, allow_fill=None):
485485
Indices to be taken. See Notes for how negative indicies
486486
are handled.
487487
fill_value : any, optional
488-
Fill value to use for NA-indicies. This has a few behaviors.
488+
Fill value to use for NA-indicies when `allow_fill` is True.
489+
This may be ``None``, in which case the default NA value for
490+
the type, ``self.dtype.na_value``, is used.
491+
allow_fill : bool, optional
492+
How to handle negative values in `indexer`.
489493
490-
* fill_value is not specified : triggers NumPy's semantics
491-
where negative values in `indexer` mean slices from the end.
492-
* fill_value is NA : Fill positions where `indexer` is ``-1``
493-
with ``self.dtype.na_value``. Anything considered NA by
494-
:func:`pandas.isna` will result in ``self.dtype.na_value``
495-
being used to fill.
496-
* fill_value is not NA : Fill positions where `indexer` is ``-1``
497-
with `fill_value`.
494+
For False values (the default), NumPy's behavior is used. Negative
495+
values in `indexer` mean slices from the right.
496+
497+
For True values, Pandas behavior is used. Indicies where `indexer`
498+
is ``-1`` are set to `fill_value`. Any other negative value should
499+
raise a ``ValueError``.
498500
499501
Returns
500502
-------
@@ -506,20 +508,10 @@ def take(self, indexer, fill_value=None, allow_fill=None):
506508
When the indexer is out of bounds for the array.
507509
ValueError
508510
When the indexer contains negative values other than ``-1``
509-
and `fill_value` is specified.
511+
and `allow_fill` is True.
510512
511513
Notes
512514
-----
513-
The meaning of negative values in `indexer` depends on the
514-
`fill_value` argument. By default, we follow the behavior
515-
:meth:`numpy.take` of where negative indices indicate slices
516-
from the end.
517-
518-
When `fill_value` is specified, we follow pandas semantics of ``-1``
519-
indicating a missing value. In this case, positions where `indexer`
520-
is ``-1`` will be filled with `fill_value` or the default NA value
521-
for this type.
522-
523515
ExtensionArray.take is called by ``Series.__getitem__``, ``.loc``,
524516
``iloc``, when the indexer is a sequence of values. Additionally,
525517
it's called by :meth:`Series.reindex` with a `fill_value`.

pandas/tests/extension/json/array.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,7 @@ def take(self, indexer, fill_value=None, allow_fill=None):
102102
msg = ("Index is out of bounds or cannot do a "
103103
"non-empty take from an empty array.")
104104

105-
if allow_fill is None:
106-
try:
107-
output = [self.data[loc] for loc in indexer]
108-
except IndexError:
109-
raise IndexError(msg)
110-
else:
105+
if allow_fill:
111106
if fill_value is None:
112107
fill_value = self.dtype.na_value
113108
# bounds check
@@ -118,6 +113,12 @@ def take(self, indexer, fill_value=None, allow_fill=None):
118113
for loc in indexer]
119114
except IndexError:
120115
raise msg
116+
else:
117+
try:
118+
output = [self.data[loc] for loc in indexer]
119+
except IndexError:
120+
raise IndexError(msg)
121+
121122
return self._from_sequence(output)
122123

123124
def copy(self, deep=False):

0 commit comments

Comments
 (0)