-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: Refactor signature of RangeIndex._simple_new #26722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REF: Refactor signature of RangeIndex._simple_new #26722
Conversation
Hello @topper-123! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-06-14 08:20:11 UTC |
e2c1f3a
to
65198ba
Compare
e6d9b4c
to
1b34ac9
Compare
Codecov Report
@@ Coverage Diff @@
## master #26722 +/- ##
==========================================
- Coverage 91.78% 91.77% -0.01%
==========================================
Files 174 174
Lines 50703 50703
==========================================
- Hits 46538 46534 -4
- Misses 4165 4169 +4
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26722 +/- ##
==========================================
- Coverage 91.86% 91.85% -0.01%
==========================================
Files 179 179
Lines 50700 50702 +2
==========================================
- Hits 46576 46574 -2
- Misses 4124 4128 +4
Continue to review full report at Codecov.
|
1b34ac9
to
40f566e
Compare
looks fine. any comments about this api change @jorisvandenbossche @TomAugspurger |
6f3471a
to
0733747
Compare
I've added a new commit that's improves the performance of slices RangeIndexes: >>> 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
>>> %timeit rng[sl.stop] # scalar
640 ns ± 15.1 ns per loop # master
652 ns ± 14.9 ns per loop # this PR, the same speed So a 4 x speed improvement for slicing. |
0733747
to
c6ce654
Compare
Ping. Is this ok? |
Is the performance improvement linked to the change in behaviour? |
No, it is because of that second commit, where we postpone the more expensive is_scalar check. It could as such be in a different PR. |
Is there a good reason to change the init behaviour? (does it make the code less complex or does it make the life easier for users?) |
5359f6b
to
6767ef0
Compare
6767ef0
to
2bde25b
Compare
I've reverted the possibility to use a Else the code is a simplification IMO by making the signature of _simple_new align with simple_new of the other the index types, which IMO help both on understanding and on typing. |
thanks @topper-123 |
This PR refactors
RangeIndex._simple_new
, so its signature is the same asIndex._simple_new
. This will help typing later on, as currently mypy complains about the different signatures. In short a_simple_new
now expects arange
as its input. As arange
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 afrom_*
class method don't have a**kwargs
part.After this PR,
RangeIndex
will be ready for adding type hints.EDIT; Performance improvements: