From 1050325fdbe9c474a22399c184ea6aa5119934c7 Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Fri, 11 Aug 2023 13:52:29 -0500 Subject: [PATCH] Fix an issue with fetching `NA` from a `TimedeltaColumn` (#13853) Fixes: #13851 This PR fixes a mistake in `_get_np_scalar_from_timedelta64`, which has to return `cudf.NA` instead of `None`. Authors: - GALI PREM SAGAR (https://github.com/galipremsagar) Approvers: - Lawrence Mitchell (https://github.com/wence-) - Bradley Dice (https://github.com/bdice) URL: https://github.com/rapidsai/cudf/pull/13853 --- python/cudf/cudf/_lib/scalar.pyx | 4 ++-- python/cudf/cudf/tests/test_timedelta.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/_lib/scalar.pyx b/python/cudf/cudf/_lib/scalar.pyx index af63964bac3..0ff736b9204 100644 --- a/python/cudf/cudf/_lib/scalar.pyx +++ b/python/cudf/cudf/_lib/scalar.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. cimport cython @@ -536,7 +536,7 @@ cdef _get_np_scalar_from_timedelta64(unique_ptr[scalar]& s): cdef scalar* s_ptr = s.get() if not s_ptr[0].is_valid(): - return None + return NA cdef libcudf_types.data_type cdtype = s_ptr[0].type() diff --git a/python/cudf/cudf/tests/test_timedelta.py b/python/cudf/cudf/tests/test_timedelta.py index ab45374c119..82ef309d116 100644 --- a/python/cudf/cudf/tests/test_timedelta.py +++ b/python/cudf/cudf/tests/test_timedelta.py @@ -1437,3 +1437,8 @@ def test_timdelta_binop_tz_timestamp(op): date_tz_scalar = datetime.datetime.now(datetime.timezone.utc) with pytest.raises(NotImplementedError): op(s, date_tz_scalar) + + +def test_timedelta_getitem_na(): + s = cudf.Series([1, 2, None, 3], dtype="timedelta64[ns]") + assert s[2] is cudf.NA