Skip to content

datetime slices with multiindex unexplained behaviour #11474

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

Closed
thrasibule opened this issue Oct 29, 2015 · 3 comments
Closed

datetime slices with multiindex unexplained behaviour #11474

thrasibule opened this issue Oct 29, 2015 · 3 comments
Labels
Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex Strings String extension data type and string data

Comments

@thrasibule
Copy link
Contributor

I don't think this is related to #9732 or #10331, but maybe I'm missing something.

index = pd.MultiIndex.from_product([pd.date_range('2015-01-01', '2015-04-01', freq='8H'), ['A', 'B', 'C']], names=['level1', 'level2'])
s = pd.Series(np.random.randn(813), index=index)

Now I'm trying to select a slice from s as follows:

idx = pd.IndexSlice
s_small = s.loc[idx['2015-01-01':'2015-01-08', :]]

Now this is very strange, if I select a slice smaller than 8 days then it works fine, but for anything bigger the selection doesn't work:

>>> s.loc[idx['2015-01-01':'2015-01-08', :]].shape #(8 days times 3 8h periods times 3 levels)
(72,)
>>> s.loc[idx['2015-01-01':'2015-01-09', :]].shape #???
(569,)
>>>
@jreback
Copy link
Contributor

jreback commented Oct 29, 2015

this is exactly #9732

partial string slicing in a multi-index is just not implemented

In [21]: s.loc[idx[pd.Timestamp('2015-01-01'):pd.Timestamp('2015-01-09'), :]].shape
Out[21]: (75L,)

@jreback jreback closed this as completed Oct 29, 2015
@jreback jreback added Datetime Datetime data dtype Indexing Related to indexing on series/frames, not to indexes themselves Strings String extension data type and string data MultiIndex Duplicate Report Duplicate issue or pull request labels Oct 29, 2015
@thrasibule
Copy link
Contributor Author

Thanks for the explicit workaround. I got confused because it was working fine for some slices.

@jreback
Copy link
Contributor

jreback commented Oct 29, 2015

yeh, partial string slicing is for 'non-production' only 😄 e.g. better to be explicit about your bounds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex Strings String extension data type and string data
Projects
None yet
Development

No branches or pull requests

2 participants