Skip to content

Commit

Permalink
Fix an issue with fetching NA from a TimedeltaColumn (#13853)
Browse files Browse the repository at this point in the history
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: #13853
  • Loading branch information
galipremsagar authored Aug 11, 2023
1 parent 6fea2df commit 1050325
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/scalar.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

cimport cython

Expand Down Expand Up @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions python/cudf/cudf/tests/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1050325

Please sign in to comment.