From 0e9a73343c4defaba59c100dca4bf288a6efde5e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 17 Jan 2024 14:53:50 -0800 Subject: [PATCH] Clean up TimedeltaIndex.__init__ constructor --- 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 e012d8e7140..00ef962d6ea 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -2840,8 +2840,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: @@ -2853,19 +2853,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)