-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
POC: Implement pythonic label-based index slicing NDFrame.slice(closed='left') #27060
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #27060 +/- ##
===========================================
- Coverage 92.04% 41.88% -50.17%
===========================================
Files 180 180
Lines 50713 50715 +2
===========================================
- Hits 46680 21243 -25437
- Misses 4033 29472 +25439
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #27060 +/- ##
===========================================
- Coverage 92.83% 41.9% -50.94%
===========================================
Files 182 180 -2
Lines 50430 50842 +412
===========================================
- Hits 46815 21303 -25512
- Misses 3615 29539 +25924
Continue to review full report at Codecov.
|
What is the use case that makes this necessary? I get that matching python slicing is desirable if we were starting from scratch, but we’ve got a lot of inertia. |
The indexer portion wasn't meant for merging. I couldn't find an explanation of why the choice was made, so I just went ahead and did it to see if I would hit a hurdle. Linked issue now has a suggestion of adding a Most pandas interval-like things (Interval, Rolling) treat all cases equally by having a |
It's been a month without any response from maintainers here or in the issue. Writing on the wall. |
@pilkibun Thanks for working on this.
There needs to be agreement on the api design before discussing the details of the implementation. I think there is some overlap with #27363 with regards to api design. There has been some discussion in #27363 regarding the api design. the current implementation there uses IMO if that PR gets merged then it would be logical, for consistency, to use |
I still agree with #27363 (comment) so neither should be merged IMHO. |
Suggested new alternative in #27363 (comment), converting |
Note: this began as a POC for an additional indexer
loc_left
, which has now been updated to become the low-level API used for providing theNDFrame.slice
functionality.WIP/POC for #27059. In short,
loc
was designed with unpythonic right-inclusive semantics, and for dubious considerations. It would be an improvement to treat slicing as taking aclosed
argument, as many pieces of pandas functionality do, such asRolling
,Interval
.Adds a
loc_left
indexer to complementsloc
. This could be made private.Adds an
NDFrame.slice
method is discussed in Discussion: Why is loc label-based slicing right-inclusive? #27059 which mimics python'sslice
signature, with the addition of aclosed
keyword. The default is 'left' to match pythonic convention.The indexer reuses the loc machinery with very few changes, and passes a test suite which augments the existing tests for loc.
implement and test
loc_left[]
implement and test
slice(closed=left/both)
implement and test
slice(closed=right/neither)
Note: #27209 by @simonjayhawkins enhances
IndexSlice
with aclosed
argument instead of introducing a new indexer.slice
could be adapted to make use of that if desired.Examples: