Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

## Bug Fixes

- PR #6073 Fix issue related to `.loc` incase of `DatetimeIndex`

# cuDF 0.15.0 (Date TBD)

Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ def find_first_value(self, value, closest=False):
Returns offset of first value that matches
"""
value = pd.to_datetime(value)
value = column.as_column(value).as_numerical[0]
value = column.as_column(value, dtype=self.dtype).as_numerical[0]
return self.as_numerical.find_first_value(value, closest=closest)

def find_last_value(self, value, closest=False):
"""
Returns offset of last value that matches
"""
value = pd.to_datetime(value)
value = column.as_column(value).as_numerical[0]
value = column.as_column(value, dtype=self.dtype).as_numerical[0]
return self.as_numerical.find_last_value(value, closest=closest)

@property
Expand Down
33 changes: 28 additions & 5 deletions python/cudf/cudf/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,22 @@ def test_series_loc_numerical():
assert_eq(ps.loc[[5, 8, 9]], gs.loc[cupy.array([5, 8, 9])])


def test_series_loc_float_index():
ps = pd.Series([1, 2, 3, 4, 5], index=[5.43, 6.34, 7.34, 8.0, 9.1])
gs = Series.from_pandas(ps)

assert_eq(ps.loc[5.43], gs.loc[5.43])
assert_eq(ps.loc[8], gs.loc[8])
assert_eq(ps.loc[6.1:8], gs.loc[6.1:8])
assert_eq(ps.loc[:7.1], gs.loc[:7.1])
assert_eq(ps.loc[6.345:], gs.loc[6.345:])
assert_eq(ps.loc[::2], gs.loc[::2])
assert_eq(
ps.loc[[True, False, True, False, True]],
gs.loc[[True, False, True, False, True]],
)


def test_series_loc_string():
ps = pd.Series(
[1, 2, 3, 4, 5], index=["one", "two", "three", "four", "five"]
Expand Down Expand Up @@ -411,11 +427,12 @@ def test_series_loc_datetime():
assert_eq(ps.loc["2001-01-02":], gs.loc["2001-01-02":], **kwargs)
assert_eq(ps.loc[:"2001-01-04"], gs.loc[:"2001-01-04"], **kwargs)
assert_eq(ps.loc[::2], gs.loc[::2], **kwargs)
#
# assert_eq(ps.loc[['2001-01-01', '2001-01-04', '2001-01-05']],
# gs.loc[['2001-01-01', '2001-01-04', '2001-01-05']])
# looks like a bug in Pandas doesn't let us check for the above,
# so instead:

assert_eq(
ps.loc[["2001-01-01", "2001-01-04", "2001-01-05"]],
gs.loc[["2001-01-01", "2001-01-04", "2001-01-05"]],
)

assert_eq(
ps.loc[
[
Expand All @@ -438,6 +455,12 @@ def test_series_loc_datetime():
**kwargs,
)

just_less_than_max = ps.index.max() - pd.Timedelta("5m")

assert_eq(
ps.loc[:just_less_than_max], gs.loc[:just_less_than_max], **kwargs
)


def test_series_loc_categorical():
ps = pd.Series(
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/utils/cudautils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def find_index_of_val(arr, val, mask=None, compare="eq"):
mask : mask of the array
compare: str ('gt', 'lt', or 'eq' (default))
"""
found = cuda.device_array_like(arr)
found = cuda.device_array(arr.shape, dtype=np.dtype("int32"))
if found.size > 0:
if compare == "gt":
gpu_mark_gt.forall(found.size)(arr, val, found, arr.size)
Expand Down