-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Partial string matching for timestamps with multiindex #10331
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
Comments
this is almost a dupe of #9732 |
@jreback, per our discussion, I have an implementation that seems to fix this issue (in the private branch above), but it does not fail the test for These tests all pass: |
Additionally, The cause is that the code in if isinstance(start, slice) or isinstance(stop, slice):
# we have a slice for start and/or stop
# a partial date slicer on a DatetimeIndex generates a slice
# note that the stop ALREADY includes the stopped point (if
# it was a string sliced)
return convert_indexer(start.start, stop.stop, step) Please let me know how you'd like me to proceed with the pull request. |
thanks @markroth8 I will be visting this next week. |
While trying to update the docs, I think I found an issue with the implementation. I'm not sure if it's new: dft2 = DataFrame(randn(200000,1),columns=['A'],index=MultiIndex.from_product([dft.index, ['a', 'b']]))
Note how rows with 'b' are only present for '2013-03' rows but 'a' appears for all rows. |
Confirmed the same behavior exists in master branch with:
Is this a bug we should file separately? |
@jreback, see my above note on dft2.loc[IndexSlice['2013-03':'2013-03',:],:]. Should I file a bug on this? |
@markroth8 yes that is a separate bug. Pls open a new issue (you can use the ex that you put in the whatsnew for a repro). |
This bug still exists in version 0.24.2. |
If you have a reproducible example I would recommend opening a new issue.
…On Wed, Jun 19, 2019 at 4:53 AM Ian Zhang ***@***.***> wrote:
Additionally, df_swap.loc[idx[:, '2016-01-02':], :] fails with an error,
but I believe this can be considered a separate bug, as it did so before my
proposed fix.
The cause is that the code in multi.py is trying to call .stop on an int
instead of first checking to see if stop is a slice:
if isinstance(start, slice) or isinstance(stop, slice):
# we have a slice for start and/or stop
# a partial date slicer on a DatetimeIndex generates a slice
# note that the stop ALREADY includes the stopped point (if
# it was a string sliced)
return convert_indexer(start.start, stop.stop, step)
Please let me know how you'd like me to proceed with the pull request.
This bug still exists in version 0.24.2.
see this SO question
<https://stackoverflow.com/questions/56616824/indexslice-on-a-datetime-multindex-not-working-but-doesnt-seem-different-from/56664818#56664818>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#10331?email_source=notifications&email_token=AAKAOIQIEU2A5MYNOFQK4M3P3H6ZZA5CNFSM4BH7XRJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYBK2AQ#issuecomment-503491842>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAKAOIUIKRUJTIGI7AQPFDLP3H6ZZANCNFSM4BH7XRJA>
.
|
I can demonstrate the issue occuring/not-occuring. It depends on whether the index is Dates only, or DateTimes.
|
I'm trying to get a slice from a multiindex. I find the behavior pretty inconsistent. Here is a simple dataframe:
With a single index, I can select all the data for a given day as follows:
But it doesn't work for a multiindex:
So I can make it work if I specify the slice explicitely, but it would be nice if the behavior for the 1D index carried over to Multiindices.
The text was updated successfully, but these errors were encountered: