Skip to content
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

[BUG] loc returning incorrect results for DatetimeIndex that is in monotonically decreasing #15742

Closed
galipremsagar opened this issue May 14, 2024 · 0 comments · Fixed by #15761
Assignees
Labels
bug Something isn't working cudf.pandas Issues specific to cudf.pandas

Comments

@galipremsagar
Copy link
Contributor

Describe the bug
When we perform a sliced loc on a DatetimeIndex that is monotonically decreasing, the result doesn't match with pandas.

Steps/Code to reproduce bug

In [1]: import cudf

In [4]: df = cudf.DataFrame({'a': [1, 1, 1, 2, 2], 'b': [1,2 ,3, 4, 5]}, index=cudf.Index([15, 14, 12, 10, 1], dtype='datetime64[ns]'))

In [5]: df
Out[5]: 
                               a  b
1970-01-01 00:00:00.000000015  1  1
1970-01-01 00:00:00.000000014  1  2
1970-01-01 00:00:00.000000012  1  3
1970-01-01 00:00:00.000000010  2  4
1970-01-01 00:00:00.000000001  2  5


In [9]: import pandas as pd

In [10]: pd.Timestamp("1970-01-01 00:00:00.000000010")
Out[10]: Timestamp('1970-01-01 00:00:00.000000010')

In [11]: i = pd.Timestamp("1970-01-01 00:00:00.000000010")

In [12]: df.loc[i:]
Out[12]: 
                               a  b
1970-01-01 00:00:00.000000015  1  1
1970-01-01 00:00:00.000000014  1  2
1970-01-01 00:00:00.000000012  1  3
1970-01-01 00:00:00.000000010  2  4

In [13]: df.to_pandas().loc[i:]
Out[13]: 
                               a  b
1970-01-01 00:00:00.000000010  2  4
1970-01-01 00:00:00.000000001  2  5

Expected behavior
Match pandas.

@galipremsagar galipremsagar added bug Something isn't working cudf.pandas Issues specific to cudf.pandas labels May 14, 2024
@galipremsagar galipremsagar self-assigned this May 14, 2024
rapids-bot bot pushed a commit that referenced this issue May 16, 2024
Fixes: #15742 

This PR resolves issues with returning incorrect ranges for `DatetimeIndex.loc` when the index objects are monotonically decreasing. Additionally, I went ahead and fixed it for all cases, (i.e., random ordering) too.

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Matthew Roeschke (https://github.com/mroeschke)

URL: #15761
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cudf.pandas Issues specific to cudf.pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant