A small, complete example of the issue
import pandas
idx = pandas.date_range("2012", "2016", freq="D")
df = pandas.concat([
pandas.DataFrame(1, index=idx, columns=[ctry]) for ctry in ["BE", "FR", "SP"]
],
axis=1).stack().to_frame()
df.index = df.index.swaplevel(0, 1)
df = df.sortlevel()
df.info()
print()
df_ok = df.loc[pandas.IndexSlice[("SP", "FR"), "2013-01-01":"2014-01-01"], :]
print()
# here, the time indexation is not properly handled as dates < 2013-01-01 are kept
df_not_ok=df.loc[pandas.IndexSlice[("SP", "BE", "FR"), "2013-01-01":"2014-01-01"], :]
Expected Output
Actual output
Output of pd.show_versions()
Comment From: jreback
This is on 0.19.rc1, though IIRC this is fixed in 0.18.1
In [13]: df.loc[pandas.IndexSlice[("SP"), "2013-01-01":"2014-01-01"], :].info()
<class 'pandas.core.frame.DataFrame'>
MultiIndex: 366 entries, (SP, 2013-01-01 00:00:00) to (SP, 2014-01-01 00:00:00)
Data columns (total 1 columns):
0 366 non-null int64
dtypes: int64(1)
memory usage: 5.7+ KB
In [15]: df.loc[pandas.IndexSlice[("SP", "BE", "SP"), "2013-01-01":"2014-01-01"], :].info()
<class 'pandas.core.frame.DataFrame'>
MultiIndex: 732 entries, (BE, 2013-01-01 00:00:00) to (SP, 2014-01-01 00:00:00)
Data columns (total 1 columns):
0 732 non-null int64
dtypes: int64(1)
memory usage: 11.4+ KB
In [16]: df.loc[pandas.IndexSlice[("SP", "BE", "FR"), "2013-01-01":"2014-01-01"], :].info()
<class 'pandas.core.frame.DataFrame'>
MultiIndex: 1098 entries, (BE, 2013-01-01 00:00:00) to (SP, 2014-01-01 00:00:00)
Data columns (total 1 columns):
0 1098 non-null int64
dtypes: int64(1)
memory usage: 17.2+ KB