Skip to content

Commit 829ec28

Browse files
Explicitly raise ValueError in RangeIndex.take when allow_fill is True and fill_value is not None
1 parent 64a2d4d commit 829ec28

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
@@ -1117,8 +1117,14 @@ def take(
11171117
if is_scalar(indices):
11181118
raise TypeError("Expected indices to be array-like")
11191119
indices = ensure_platform_int(indices)
1120-
allow_fill = self._maybe_disallow_fill(allow_fill, fill_value, indices)
1121-
assert allow_fill is False, "allow_fill isn't supported by RangeIndex"
1120+
1121+
# If allow_fill=True and fill_value=None, just ignore allow_fill,
1122+
# without raising an exception, as it's done in the base class.
1123+
if allow_fill and fill_value is not None:
1124+
cls_name = type(self).__name__
1125+
raise ValueError(
1126+
f"Unable to fill values because {cls_name} cannot contain NA"
1127+
)
11221128

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

0 commit comments

Comments
 (0)