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

Fix Index.repeat for datetime64 types #15722

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,9 +1515,12 @@ def argsort(
)

def repeat(self, repeats, axis=None):
return self._from_columns_like_self(
res = self._from_columns_like_self(
Frame._repeat([*self._columns], repeats, axis), self._column_names
)
if isinstance(res, DatetimeIndex):
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
res._freq = None
return res

@_cudf_nvtx_annotate
def where(self, cond, other=None, inplace=False):
Expand Down
5 changes: 4 additions & 1 deletion python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4871,13 +4871,16 @@ def repeat(self, repeats, axis=None):
1 2
dtype: int64
"""
return self._from_columns_like_self(
res = self._from_columns_like_self(
Frame._repeat(
[*self._index._data.columns, *self._columns], repeats, axis
),
self._column_names,
self._index_names,
)
if isinstance(res.index, cudf.DatetimeIndex):
res.index._freq = None
return res

def astype(
self,
Expand Down
14 changes: 14 additions & 0 deletions python/cudf/cudf/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3251,3 +3251,17 @@ def test_Index_init_with_nans():
assert gi.dtype == np.dtype("float64")
pi = pd.Index([1, 2, 3, np.nan])
assert_eq(pi, gi)


def test_index_datetime_repeat():
gidx = cudf.date_range("2021-01-01", periods=3, freq="D")
pidx = gidx.to_pandas()

actual = gidx.repeat(5)
expected = pidx.repeat(5)

assert_eq(actual, expected)

actual = gidx.to_frame().repeat(5)

assert_eq(actual.index, expected)
Loading