DatetimeIndex._maybe_cast_slice_bound with duplicates · Issue #16515 · pandas-dev/pandas (original) (raw)

DatetimeIndex._maybe_cast_slice_bound can return the wrong value when you have an index that is monotonically decreasing, but not strictly monotonically decreasing.

In [1]: import pandas as pd

In [2]: pd.DatetimeIndex(['2017', '2017']) Out[2]: DatetimeIndex(['2017-01-01', '2017-01-01'], dtype='datetime64[ns]', freq=None)

In [3]: pd.DatetimeIndex(['2017', '2017'])._maybe_cast_slice_bound('2017-01-01', 'left', 'loc') Out[3]: Timestamp('2017-01-01 23:59:59.999999999')

The issue is here That check really needs to check for strict monotonic decreasing, not just monotonic decreasing.

Have we hit any other needs for strict monotonic algos? This is such an extreme edge case, not sure it's worthwhile on its own.

Came up in dask/dask#2389