API: Index.take inconsistently handle fill_value · Issue #12631 · pandas-dev/pandas (original) (raw)

Normal Index ignores fill_value (this is desribed in docstring)

pd.Index([1, 2, 3]).take(np.array([1, 0, -1]), fill_value=np.nan)
# Int64Index([2, 1, 3], dtype='int64')

But DatetimeIndex does (used in reshape ops at least).

pd.DatetimeIndex(['2011-01-01', '2011-02-01', '2011-03-01'], tz='US/Eastern').take(np.array([1, 0, -1]), fill_value=pd.NaT)
# DatetimeIndex(['2011-02-01 00:00:00-05:00', '2011-01-01 00:00:00-05:00',
#                'NaT'],
#               dtype='datetime64[ns, US/Eastern]', freq=None)

Otherwise PeriodIndex doesn't.

pd.PeriodIndex(['2011-01', '2011-02', '2011-03'], freq='M').take(np.array([1, 0, -1]), fill_value=pd.NaT)
# PeriodIndex(['2011-02', '2011-01', '2011-03'], dtype='int64', freq='M')

So I'd like to discuss:

  1. All Index should handle fill_value?
  2. Only PeriodIndex should handle fill_value to be compat with other datetime-likes.