Skip to content

DatetimeIndex.insert works with only positive values #7256

@benjaminmgross

Description

@benjaminmgross

Consider allowing negative values for loc parameter of DatetimeIndex.insert(loc, item). Currently, negative parameters result in an "off by 1" return value. For example:

In [ 1]: index = pandas.DatetimeIndex(start = '01/01/2000', freq = 'B', periods = 5) In [ 2]: dt = pandas.Timestamp('01/01/2013') In [ 3]: new_ind = index.insert(-1, dt) In [ 4]: new_ind[-1] Out[ 4]: Timestamp('2000-01-07 00:00:00', tz=None) 

But:

In [ 5]: new_ind[-2] Out[ 5]: Timestamp('2013-01-01 00:00:00', tz=None) 

I can put together a quick fork if it's a change you'd like. If not, I think it makes sense to change the docstring to say that "negative values are not allowed."

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions