Skip to content

Commit 0ecc3d9

Browse files
Explicitly raise ValueError in RangeIndex.take when allow_fill is True and fill_value is not None
1 parent a8e8361 commit 0ecc3d9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pandas/core/indexes/range.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,14 @@ def take(
11201120
if is_scalar(indices):
11211121
raise TypeError("Expected indices to be array-like")
11221122
indices = ensure_platform_int(indices)
1123-
allow_fill = self._maybe_disallow_fill(allow_fill, fill_value, indices)
1124-
assert allow_fill is False, "allow_fill isn't supported by RangeIndex"
1123+
1124+
# If allow_fill=True and fill_value=None, just ignore allow_fill,
1125+
# without raising an exception, as it's done in the base class.
1126+
if allow_fill and fill_value is not None:
1127+
cls_name = type(self).__name__
1128+
raise ValueError(
1129+
f"Unable to fill values because {cls_name} cannot contain NA"
1130+
)
11251131

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

0 commit comments

Comments
 (0)