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

Index._maybe_cast_slice_bound switched meaning of left/right #14354

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

Comments

Projects
None yet
4 participants
@mrocklin
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

This comment has been minimized.

Show comment
Hide comment
@jorisvandenbossche

jorisvandenbossche Oct 5, 2016

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
Member

jorisvandenbossche commented Oct 5, 2016

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

This comment has been minimized.

Show comment
Hide comment
@chris-b1

chris-b1 Oct 5, 2016

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@mrocklin

mrocklin Oct 5, 2016

Contributor

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
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Oct 6, 2016

Contributor

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

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).

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