From 0c2c7a1dc4a556722a3bd28c9188f4fdc84d229f Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 27 Apr 2021 12:46:12 -0700 Subject: [PATCH] Add missing __cuda_array_interface__ for datetime objects. --- python/cudf/cudf/core/column/datetime.py | 31 +++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/python/cudf/cudf/core/column/datetime.py b/python/cudf/cudf/core/column/datetime.py index b9d42c031c7..d86a54e6970 100644 --- a/python/cudf/cudf/core/column/datetime.py +++ b/python/cudf/cudf/core/column/datetime.py @@ -2,10 +2,12 @@ from __future__ import annotations +import builtins import datetime as dt import re from numbers import Number -from typing import Any, Sequence, Union, cast +from types import SimpleNamespace +from typing import Any, Mapping, Sequence, Union, cast import numpy as np import pandas as pd @@ -199,6 +201,33 @@ def as_numerical(self) -> "cudf.core.column.NumericalColumn": ), ) + @property + def __cuda_array_interface__(self) -> Mapping[builtins.str, Any]: + output = { + "shape": (len(self),), + "strides": (self.dtype.itemsize,), + "typestr": self.dtype.str, + "data": (self.data_ptr, False), + "version": 1, + } + + if self.nullable and self.has_nulls: + + # Create a simple Python object that exposes the + # `__cuda_array_interface__` attribute here since we need to modify + # some of the attributes from the numba device array + mask = SimpleNamespace( + __cuda_array_interface__={ + "shape": (len(self),), + "typestr": " DatetimeColumn: dtype = np.dtype(dtype) if dtype == self.dtype: