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

API: Index.take inconsistently handle fill_value #12631

Closed
sinhrks opened this Issue Mar 15, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@sinhrks
Member

sinhrks commented Mar 15, 2016

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.

@sinhrks sinhrks added this to the 0.18.1 milestone Mar 15, 2016

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Mar 15, 2016

Contributor

this should be supported for any indexes which support NA (IOW not RangeIndex/Int64Index). So for sure PeriodIndex (I think TimedeltaIndex already works for this). You may need to override Int64Index and fix Index to make this work.

Contributor

jreback commented Mar 15, 2016

this should be supported for any indexes which support NA (IOW not RangeIndex/Int64Index). So for sure PeriodIndex (I think TimedeltaIndex already works for this). You may need to override Int64Index and fix Index to make this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment