Skip to content

.loc slice with datetime string with DataFrame of length 1 gives an empty DataFrame #16071

Closed
@cpaulik

Description

@cpaulik

I've already raised the problem at #13929 (comment) but it turned out to be a different issue.

The following test code illustrates the problem

import pandas as pd
from pandas.util import testing as tm

from datetime import datetime
df = pd.DataFrame(columns=['1'],
                  index=pd.date_range('2016-10-01T00:00:00',
                                      '2016-10-01T23:59:59'))
df_sliced_dt = df.loc[datetime(2016,10,1):]
tm.assert_frame_equal(df, df_sliced_dt)

df = pd.DataFrame(columns=['1'],
                  index=pd.date_range('2016-10-01T00:00:00',
                                      '2016-10-01T23:59:59'))
df_sliced_str = df.loc['2016-10-01T00:00:00':]
tm.assert_frame_equal(df, df_sliced_str)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypeIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions