Skip to content

Commit

Permalink
Raise error for more cases when timezone-aware data is passed to `a…
Browse files Browse the repository at this point in the history
…s_column` (#13835)

Fixes: #13834 

This PR raises `NotImplementedError` for more types of data that are timezone-aware passed to `as_column`.

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Matthew Roeschke (https://github.com/mroeschke)
  - Bradley Dice (https://github.com/bdice)

URL: #13835
  • Loading branch information
galipremsagar authored Aug 8, 2023
1 parent 9b80bfd commit 3190938
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
16 changes: 11 additions & 5 deletions python/cudf/cudf/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,17 +454,23 @@ def is_any_real_numeric_dtype(arr_or_dtype) -> bool:
# TODO: Evaluate which of the datetime types need special handling for cudf.
is_datetime_dtype = _wrap_pandas_is_dtype_api(pd_types.is_datetime64_dtype)
is_datetime64_any_dtype = pd_types.is_datetime64_any_dtype
is_datetime64_dtype = pd_types.is_datetime64_dtype
is_datetime64_ns_dtype = pd_types.is_datetime64_ns_dtype
is_datetime64tz_dtype = pd_types.is_datetime64tz_dtype
is_datetime64_dtype = _wrap_pandas_is_dtype_api(pd_types.is_datetime64_dtype)
is_datetime64_ns_dtype = _wrap_pandas_is_dtype_api(
pd_types.is_datetime64_ns_dtype
)
is_datetime64tz_dtype = _wrap_pandas_is_dtype_api(
pd_types.is_datetime64tz_dtype
)
is_extension_type = pd_types.is_extension_type
is_extension_array_dtype = pd_types.is_extension_array_dtype
is_int64_dtype = pd_types.is_int64_dtype
is_period_dtype = pd_types.is_period_dtype
is_signed_integer_dtype = pd_types.is_signed_integer_dtype
is_timedelta_dtype = _wrap_pandas_is_dtype_api(pd_types.is_timedelta64_dtype)
is_timedelta64_dtype = pd_types.is_timedelta64_dtype
is_timedelta64_ns_dtype = pd_types.is_timedelta64_ns_dtype
is_timedelta64_dtype = _wrap_pandas_is_dtype_api(pd_types.is_timedelta64_dtype)
is_timedelta64_ns_dtype = _wrap_pandas_is_dtype_api(
pd_types.is_timedelta64_ns_dtype
)
is_unsigned_integer_dtype = pd_types.is_unsigned_integer_dtype
is_sparse = pd_types.is_sparse
# is_list_like = pd_types.is_list_like
Expand Down
19 changes: 19 additions & 0 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
infer_dtype,
is_bool_dtype,
is_categorical_dtype,
is_datetime64_dtype,
is_datetime64tz_dtype,
is_decimal32_dtype,
is_decimal64_dtype,
Expand Down Expand Up @@ -2230,6 +2231,12 @@ def as_column(
data = ColumnBase.from_scalar(arbitrary, length if length else 1)
elif isinstance(arbitrary, pd.core.arrays.masked.BaseMaskedArray):
data = as_column(pa.Array.from_pandas(arbitrary), dtype=dtype)
elif isinstance(arbitrary, pd.DatetimeIndex) and isinstance(
arbitrary.dtype, pd.DatetimeTZDtype
):
raise NotImplementedError(
"cuDF does not yet support timezone-aware datetimes"
)
else:
try:
data = as_column(
Expand Down Expand Up @@ -2279,6 +2286,18 @@ def as_column(
"Use `tz_localize()` to construct "
"timezone aware data."
)
elif is_datetime64_dtype(dtype):
# Error checking only, actual construction happens
# below.
pa_array = pa.array(arbitrary)
if (
isinstance(pa_array.type, pa.TimestampType)
and pa_array.type.tz is not None
):
raise NotImplementedError(
"cuDF does not yet support timezone-aware "
"datetimes"
)
if is_list_dtype(dtype):
data = pa.array(arbitrary)
if type(data) not in (pa.ListArray, pa.NullArray):
Expand Down
2 changes: 2 additions & 0 deletions python/cudf/cudf/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,8 @@ def test_construction_from_tz_timestamps(data):
_ = cudf.Series(data)
with pytest.raises(NotImplementedError):
_ = cudf.Index(data)
with pytest.raises(NotImplementedError):
_ = cudf.DatetimeIndex(data)


@pytest.mark.parametrize("op", _cmpops)
Expand Down

0 comments on commit 3190938

Please sign in to comment.