You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
DatetimeIndex / TimedeltaIndex
Internally,
order
may usetake
whenreturn_indexer
isTrue
and should be fixed also.PeriodIndex
Results in
TypeError
because it doesn't passfreq
(PeriodIndex
without freq is meaningless ). Required to fix #7832 first to use the same flow asDatetimeIndex
, I think.The text was updated successfully, but these errors were encountered: