Skip to content

Index._maybe_cast_slice_bound switched meaning of left/right #14354

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

Closed
mrocklin opened this issue Oct 5, 2016 · 4 comments
Closed

Index._maybe_cast_slice_bound switched meaning of left/right #14354

mrocklin opened this issue Oct 5, 2016 · 4 comments
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@mrocklin
Copy link
Contributor

mrocklin commented Oct 5, 2016

'left' and 'right' changed meaning in DatetimeIndex._maybe_cast_slice_bound. Was this intentional?

Pandas 0.18

In [1]: import pandas as pd

In [2]: index = pd.DatetimeIndex(freq='1H', periods=0, end='2015')

In [3]: index._maybe_cast_slice_bound('2015-01-02', 'right', 'loc')
Out[3]: Timestamp('2015-01-02 23:59:59.999999999')

In [4]: index._maybe_cast_slice_bound('2015-01-02', 'left', 'loc')
Out[4]: Timestamp('2015-01-02 00:00:00')

Pandas 0.19

In [1]: import pandas as pd

In [2]: index = pd.DatetimeIndex(freq='1H', periods=0, end='2015')

In [3]: index._maybe_cast_slice_bound('2015-01-02', 'right', 'loc')
Out[3]: Timestamp('2015-01-02 00:00:00')

In [4]: index._maybe_cast_slice_bound('2015-01-02', 'left', 'loc')
Out[4]: Timestamp('2015-01-02 23:59:59.999999999')
@jorisvandenbossche
Copy link
Member

This is related to #14317

But the reason this is now different, is because the index thinks it is monotonic decreasing:

In [20]: index = pd.DatetimeIndex(freq='1H', periods=0, end='2015')

In [21]: index.is_monotonic_decreasing
Out[21]: True

@chris-b1
Copy link
Contributor

chris-b1 commented Oct 5, 2016

Yeah, maybe should reverse this conditional and make is_monotonic_increasing the assumption for a length 0 index?

https://github.com/pydata/pandas/pull/14317/files#diff-23ecb29e7ceba52109a365e447400d2eR1454

@mrocklin
Copy link
Contributor Author

mrocklin commented Oct 5, 2016

Interestingly it is both:

In [4]: index
Out[4]: DatetimeIndex([], dtype='datetime64[ns]', freq='H')

In [5]: index.is_monotonic_increasing
Out[5]: True

In [6]: index.is_monotonic_decreasing
Out[6]: True

@jreback
Copy link
Contributor

jreback commented Oct 6, 2016

yeah I think this needs an adjustment to non-pick the decreasing case when both are true. (or just special case on empty).

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Difficulty Novice labels Oct 6, 2016
@jreback jreback added this to the 0.19.1 milestone Oct 6, 2016
jcrist added a commit to mrocklin/dask that referenced this issue Oct 6, 2016
jcrist added a commit to dask/dask that referenced this issue Oct 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

4 participants