Skip to content
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
Closed

API: Index.take inconsistently handle fill_value #12631

sinhrks opened this issue Mar 15, 2016 · 1 comment
Labels
API Design Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type
Milestone

Comments

@sinhrks
Copy link
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 Indexing Related to indexing on series/frames, not to indexes themselves API Design Period Period data type labels Mar 15, 2016
@sinhrks sinhrks added this to the 0.18.1 milestone Mar 15, 2016
@jreback
Copy link
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
Labels
API Design Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants