REF: Refactor signature of RangeIndex._simple_new by topper-123 · Pull Request #26722 · pandas-dev/pandas (original) (raw)
This PR refactors RangeIndex._simple_new
, so its signature is the same as Index._simple_new
. This will help typing later on, as currently mypy complains about the different signatures. In short a _simple_new
now expects a range
as its input. As a range
is immutable, the code is easy to reason about.
Additionally, the signature of RangeIndex.from_range
has dropped the **kwargs
part of its signature. This makes the class method a bit easier to reason about. Other classes with a from_*
class method don't have a **kwargs
part.
After this PR, RangeIndex
will be ready for adding type hints.
EDIT; Performance improvements:
rng = pd.RangeIndex(1_000_000) sl = slice(0, 900_000) %timeit rng[sl] # slicing 7.65 µs ± 8.11 ns per loop # master 1.85 µs ± 8.11 ns per loop # this PR