From d017cf498212f27bb8954cf6c698aa754fe9c8e1 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 19 Jan 2024 07:38:29 -1000 Subject: [PATCH] Clean up `TimedeltaIndex.__init__` constructor (#14775) Aligns the constructor closer to `DatetimeIndex.__init__`: https://github.com/rapidsai/cudf/pull/14774 Authors: - Matthew Roeschke (https://github.com/mroeschke) - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Vyas Ramasubramani (https://github.com/vyasr) URL: https://github.com/rapidsai/cudf/pull/14775 --- python/cudf/cudf/core/index.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python/cudf/cudf/core/index.py b/python/cudf/cudf/core/index.py index 96643ef08d3..fa7173f1d0f 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -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: @@ -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)