Skip to content

BUG/API: Datetime-like Index.order reset freq #10295

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
sinhrks opened this issue Jun 6, 2015 · 3 comments
Closed

BUG/API: Datetime-like Index.order reset freq #10295

sinhrks opened this issue Jun 6, 2015 · 3 comments
Labels
Datetime Datetime data dtype Frequency DateOffsets Period Period data type Timedelta Timedelta data type
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Jun 6, 2015

DatetimeIndex / TimedeltaIndex

import pandas as pd
idx = pd.date_range('2011-01-01', '2011-05-01', freq='M')

# freq must be preserved, because ``DatetimeIndex`` is ordered when it has freq
idx.order()
# DatetimeIndex(['2011-01-31', '2011-02-28', '2011-03-31', '2011-04-30'], dtype='datetime64[ns]', freq=None, tz=None)

# freq must be preserved like idx[::-1]
idx.order(ascending=False)
# DatetimeIndex(['2011-04-30', '2011-03-31', '2011-02-28', '2011-01-31'], dtype='datetime64[ns]', freq=None, tz=None)

idx[::-1]
# DatetimeIndex(['2011-04-30', '2011-03-31', '2011-02-28', '2011-01-31'], dtype='datetime64[ns]', freq='-1M', tz=None)

Internally, order may use take when return_indexer is True and should be fixed also.

PeriodIndex

Results in TypeError because it doesn't pass freq ( PeriodIndex without freq is meaningless ). Required to fix #7832 first to use the same flow as DatetimeIndex, I think.

idx = pd.period_range('2011-01-01', '2011-05-01', freq='M')
idx.order()
# TypeError: expected string or buffer

idx.order().freq is None
# True
@sinhrks sinhrks added Datetime Datetime data dtype Timedelta Timedelta data type Frequency DateOffsets Period Period data type labels Jun 6, 2015
@sinhrks sinhrks added this to the 0.17.0 milestone Jun 6, 2015
@sinhrks
Copy link
Member Author

sinhrks commented Jun 6, 2015

Found another issue related to this internally.

Index.take raises IndexError if given indices are not in the index.

import pandas as pd

idx = pd.Index([0, 1, 2])
# Int64Index([0, 1, 2], dtype='int64')

idx.take([0, 1, 2, 3])
# IndexError: index 3 is out of bounds for size 3

But DatetimeIndex and TimedeltaIndex don't if given index is looks like a slice.

didx = pd.DatetimeIndex(['2011-01-01', '2011-01-02', '2011-01-03'])

# NG IndexError not raised
dtidx.take([0, 1, 2, 3])
# DatetimeIndex(['2011-01-01', '2011-01-02', '2011-01-03'], dtype='datetime64[ns]', freq=None, tz=None)

dtidx = pd.TimedeltaIndex(['1 day', '2 day', '3 day'])
dtidx.take([0, 1, 2, 3])
# TimedeltaIndex(['1 days', '2 days', '3 days'], dtype='timedelta64[ns]', freq=None)

# normal slicing results in IndexError (OK)
didx[[0, 1, 2, 3]]
# IndexError: index 3 is out of bounds for axis 1 with size 3

@jreback
Copy link
Contributor

jreback commented Jun 14, 2015

these need some wrapping on the return e.g. _shallow_copy.

@sinhrks
Copy link
Member Author

sinhrks commented Jun 23, 2015

#10305 intends to fix this, passing existing attribtues to _simple_new.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Frequency DateOffsets Period Period data type Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

2 participants