@@ -740,44 +740,36 @@ def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
740
740
if kwargs :
741
741
nv .validate_take (tuple (), kwargs )
742
742
indices = ensure_platform_int (indices )
743
- if self ._can_hold_na :
744
- taken = self ._assert_take_fillable (
745
- self ._values ,
746
- indices ,
747
- allow_fill = allow_fill ,
748
- fill_value = fill_value ,
749
- na_value = self ._na_value ,
750
- )
751
- else :
752
- if allow_fill and fill_value is not None :
753
- cls_name = type (self ).__name__
754
- raise ValueError (
755
- f"Unable to fill values because { cls_name } cannot contain NA"
756
- )
757
- taken = self ._values .take (indices )
743
+ allow_fill = self ._maybe_disallow_fill (allow_fill , fill_value , indices )
744
+
745
+ # Note: we discard fill_value and use self._na_value, only relevant
746
+ # in the case where allow_fill is True and fill_value is not None
747
+ taken = algos .take (
748
+ self ._values , indices , allow_fill = allow_fill , fill_value = self ._na_value
749
+ )
758
750
return self ._shallow_copy (taken )
759
751
760
- def _assert_take_fillable (
761
- self , values , indices , allow_fill = True , fill_value = None , na_value = np .nan
762
- ):
752
+ def _maybe_disallow_fill (self , allow_fill : bool , fill_value , indices ) -> bool :
763
753
"""
764
- Internal method to handle NA filling of take.
754
+ We only use pandas-style take when allow_fill is True _and_
755
+ fill_value is not None.
765
756
"""
766
- indices = ensure_platform_int (indices )
767
-
768
- # only fill if we are passing a non-None fill_value
769
757
if allow_fill and fill_value is not None :
770
- if (indices < - 1 ).any ():
758
+ # only fill if we are passing a non-None fill_value
759
+ if self ._can_hold_na :
760
+ if (indices < - 1 ).any ():
761
+ raise ValueError (
762
+ "When allow_fill=True and fill_value is not None, "
763
+ "all indices must be >= -1"
764
+ )
765
+ else :
766
+ cls_name = type (self ).__name__
771
767
raise ValueError (
772
- "When allow_fill=True and fill_value is not None, "
773
- "all indices must be >= -1"
768
+ f"Unable to fill values because { cls_name } cannot contain NA"
774
769
)
775
- taken = algos .take (
776
- values , indices , allow_fill = allow_fill , fill_value = na_value
777
- )
778
770
else :
779
- taken = algos . take ( values , indices , allow_fill = False , fill_value = na_value )
780
- return taken
771
+ allow_fill = False
772
+ return allow_fill
781
773
782
774
_index_shared_docs [
783
775
"repeat"
0 commit comments