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

This is related to pydata#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
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 referenced this issue in dask/dask Oct 5, 2016

Merged

Test pandas 0.19.0 rc1 #1540

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
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 added this to the 0.19.1 milestone Oct 6, 2016

@jcrist jcrist added a commit to mrocklin/dask that referenced this issue Oct 6, 2016

@jcrist jcrist Use a nonempty index in _maybe_partial_time_string
Fixes the regression due to
pandas-dev/pandas#14354.
24521a9

@jcrist jcrist added a commit to dask/dask that referenced this issue Oct 6, 2016

@jcrist jcrist Use a nonempty index in _maybe_partial_time_string
Fixes the regression due to
pandas-dev/pandas#14354.
10af53a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment