Skip to content

DatetimeIndex._maybe_cast_slice_bound with duplicates #16515

Closed
@TomAugspurger

Description

@TomAugspurger

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffDatetimeDatetime data dtypeIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions