Skip to content

Commit 4964d81

Browse files
Explicitly raise ValueError in RangeIndex.take when allow_fill is True and fill_value is not None
1 parent 9065c18 commit 4964d81

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pandas/core/indexes/range.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,14 @@ def take(
10521052
if is_scalar(indices):
10531053
raise TypeError("Expected indices to be array-like")
10541054
indices = ensure_platform_int(indices)
1055-
allow_fill = self._maybe_disallow_fill(allow_fill, fill_value, indices)
1056-
assert allow_fill is False, "allow_fill isn't supported by RangeIndex"
1055+
1056+
# If allow_fill=True and fill_value=None, just ignore allow_fill,
1057+
# without raising an exception, as it's done in the base class.
1058+
if allow_fill and fill_value is not None:
1059+
cls_name = type(self).__name__
1060+
raise ValueError(
1061+
f"Unable to fill values because {cls_name} cannot contain NA"
1062+
)
10571063

10581064
if len(indices) == 0:
10591065
taken = np.array([], dtype=self.dtype)

0 commit comments

Comments
 (0)