Skip to content

Commit

Permalink
Clean up TimedeltaIndex.__init__ constructor (#14775)
Browse files Browse the repository at this point in the history
Aligns the constructor closer to `DatetimeIndex.__init__`: #14774

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #14775
  • Loading branch information
mroeschke authored Jan 19, 2024
1 parent aba34fd commit d017cf4
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2838,8 +2838,8 @@ def __init__(
unit=None,
freq=None,
closed=None,
dtype="timedelta64[ns]",
copy=False,
dtype=None,
copy: bool = False,
name=None,
):
if freq is not None:
Expand All @@ -2851,19 +2851,19 @@ def __init__(
"dtype parameter is supported"
)

valid_dtypes = tuple(
f"timedelta64[{res}]" for res in ("s", "ms", "us", "ns")
)
if dtype not in valid_dtypes:
raise TypeError("Invalid dtype")
if dtype is None:
dtype = "timedelta64[ns]"
dtype = cudf.dtype(dtype)
if dtype.kind != "m":
raise TypeError("dtype must be a timedelta type")

kwargs = _setdefault_name(data, name=name)
name = _setdefault_name(data, name=name)["name"]
data = column.as_column(data, dtype=dtype)

if copy:
data = data.copy()

super().__init__(data, **kwargs)
super().__init__(data, name=name)

def __getitem__(self, index):
value = super().__getitem__(index)
Expand Down

0 comments on commit d017cf4

Please sign in to comment.