Skip to content

BUG: partial string indexing with PeriodIndex #6716

Closed
@jreback

Description

@jreback

partial indexing works with time series, but not period index

In [27]: df2 = DataFrame(np.arange(20).reshape(10,2),index=pd.date_range('20130101 09:00',freq='T',periods=10))

In [28]: df = DataFrame(np.arange(20).reshape(10,2),index=pd.period_range('20130101 09:00',freq='T',periods=10))

In [29]: df2['20130101']
Out[29]: 
                      0   1
2013-01-01 09:00:00   0   1
2013-01-01 09:01:00   2   3
2013-01-01 09:02:00   4   5
2013-01-01 09:03:00   6   7
2013-01-01 09:04:00   8   9
2013-01-01 09:05:00  10  11
2013-01-01 09:06:00  12  13
2013-01-01 09:07:00  14  15
2013-01-01 09:08:00  16  17
2013-01-01 09:09:00  18  19

[10 rows x 2 columns]

In [30]: df['20130101']
KeyError: u'no item named 20130101'

In [31]: df2['20130101 09']
Out[31]: 
                      0   1
2013-01-01 09:00:00   0   1
2013-01-01 09:01:00   2   3
2013-01-01 09:02:00   4   5
2013-01-01 09:03:00   6   7
2013-01-01 09:04:00   8   9
2013-01-01 09:05:00  10  11
2013-01-01 09:06:00  12  13
2013-01-01 09:07:00  14  15
2013-01-01 09:08:00  16  17
2013-01-01 09:09:00  18  19

[10 rows x 2 columns]

In [32]: df['20130101 09']
KeyError: u'no item named 20130101 09'

Works fine for exact start points

In [34]: df2['20130101 09:05':]
Out[34]: 
                      0   1
2013-01-01 09:05:00  10  11
2013-01-01 09:06:00  12  13
2013-01-01 09:07:00  14  15
2013-01-01 09:08:00  16  17
2013-01-01 09:09:00  18  19

[5 rows x 2 columns]

In [35]: df['20130101 09:05':]
Out[35]: 
                   0   1
2013-01-01 09:05  10  11
2013-01-01 09:06  12  13
2013-01-01 09:07  14  15
2013-01-01 09:08  16  17
2013-01-01 09:09  18  19

[5 rows x 2 columns]

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesPeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions