Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Time-zone-aware DatetimeIndex is being accepted silently by DatetimeIndex constructor #13834

Closed
galipremsagar opened this issue Aug 8, 2023 · 0 comments · Fixed by #13835
Assignees
Labels
bug Something isn't working

Comments

@galipremsagar
Copy link
Contributor

Describe the bug
We currently raise error when a time-zone-aware index is passed to cudf.Index, but not for cudf.DatetimeIndex.

Steps/Code to reproduce bug

In [1]: import pandas as pd

In [2]: import cudf

In [3]: i = pd.date_range(start="2017-01-01", periods=2, tz='UTC')

In [4]: i
Out[4]: DatetimeIndex(['2017-01-01 00:00:00+00:00', '2017-01-02 00:00:00+00:00'], dtype='datetime64[ns, UTC]', freq='D')

In [5]: cudf.Index(i)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File /nvme/0/pgali/envs/cudfdev/lib/python3.10/site-packages/cudf/core/column/column.py:2236, in as_column(arbitrary, nan_as_null, dtype, length)
   2234 try:
   2235     data = as_column(
-> 2236         memoryview(arbitrary), dtype=dtype, nan_as_null=nan_as_null
   2237     )
   2238 except TypeError:

TypeError: memoryview: a bytes-like object is required, not 'DatetimeIndex'

During handling of the above exception, another exception occurred:

NotImplementedError                       Traceback (most recent call last)
Cell In[5], line 1
----> 1 cudf.Index(i)

File /nvme/0/pgali/envs/cudfdev/lib/python3.10/site-packages/nvtx/nvtx.py:101, in annotate.__call__.<locals>.inner(*args, **kwargs)
     98 @wraps(func)
     99 def inner(*args, **kwargs):
    100     libnvtx_push_range(self.attributes, self.domain.handle)
--> 101     result = func(*args, **kwargs)
    102     libnvtx_pop_range(self.domain.handle)
    103     return result

File /nvme/0/pgali/envs/cudfdev/lib/python3.10/site-packages/cudf/core/index.py:3437, in Index.__new__(cls, data, dtype, copy, name, tupleize_cols, nan_as_null, **kwargs)
   3432 if tupleize_cols is not True:
   3433     raise NotImplementedError(
   3434         "tupleize_cols != True is not yet supported"
   3435     )
-> 3437 return as_index(
   3438     data,
   3439     copy=copy,
   3440     dtype=dtype,
   3441     name=name,
   3442     nan_as_null=nan_as_null,
   3443     **kwargs,
   3444 )

File /nvme/0/pgali/envs/cudfdev/lib/python3.10/site-packages/nvtx/nvtx.py:101, in annotate.__call__.<locals>.inner(*args, **kwargs)
     98 @wraps(func)
     99 def inner(*args, **kwargs):
    100     libnvtx_push_range(self.attributes, self.domain.handle)
--> 101     result = func(*args, **kwargs)
    102     libnvtx_pop_range(self.domain.handle)
    103     return result

File /nvme/0/pgali/envs/cudfdev/lib/python3.10/site-packages/cudf/core/index.py:3336, in as_index(arbitrary, nan_as_null, **kwargs)
   3333 elif isinstance(arbitrary, cudf.DataFrame):
   3334     return cudf.MultiIndex.from_frame(arbitrary)
   3335 return as_index(
-> 3336     column.as_column(
   3337         arbitrary, dtype=kwargs.get("dtype", None), nan_as_null=nan_as_null
   3338     ),
   3339     **kwargs,
   3340 )

File /nvme/0/pgali/envs/cudfdev/lib/python3.10/site-packages/cudf/core/column/column.py:2368, in as_column(arbitrary, nan_as_null, dtype, length)
   2358     if (
   2359         isinstance(arbitrary, pd.Index)
   2360         and arbitrary.dtype == cudf.dtype("object")
   (...)
   2363         )
   2364     ):
   2365         raise MixedTypeError(
   2366             "Cannot create column with mixed types"
   2367         )
-> 2368     data = as_column(
   2369         pyarrow_array,
   2370         dtype=dtype,
   2371         nan_as_null=nan_as_null,
   2372     )
   2373 except (pa.ArrowInvalid, pa.ArrowTypeError, TypeError) as e:
   2374     if isinstance(e, MixedTypeError):

File /nvme/0/pgali/envs/cudfdev/lib/python3.10/site-packages/cudf/core/column/column.py:1987, in as_column(arbitrary, nan_as_null, dtype, length)
   1981 if isinstance(arbitrary, pa.lib.HalfFloatArray):
   1982     raise NotImplementedError(
   1983         "Type casting from `float16` to `float32` is not "
   1984         "yet supported in pyarrow, see: "
   1985         "https://issues.apache.org/jira/browse/ARROW-3802"
   1986     )
-> 1987 col = ColumnBase.from_arrow(arbitrary)
   1989 if isinstance(arbitrary, pa.NullArray):
   1990     new_dtype = cudf.dtype(arbitrary.type.to_pandas_dtype())

File /nvme/0/pgali/envs/cudfdev/lib/python3.10/site-packages/cudf/core/column/column.py:345, in ColumnBase.from_arrow(cls, array)
    339 data = pa.table([array], [None])
    341 if (
    342     isinstance(array.type, pa.TimestampType)
    343     and array.type.tz is not None
    344 ):
--> 345     raise NotImplementedError(
    346         "cuDF does not yet support timezone-aware datetimes"
    347     )
    348 if isinstance(array.type, pa.DictionaryType):
    349     indices_table = pa.table(
    350         {
    351             "None": pa.chunked_array(
   (...)
    355         }
    356     )

NotImplementedError: cuDF does not yet support timezone-aware datetimes

In [6]: cudf.DatetimeIndex(i)
Out[6]: DatetimeIndex(['2017-01-01', '2017-01-02'], dtype='datetime64[ns]')

Expected behavior
Raise error similar to cudf.Index

Environment overview (please complete the following information)

  • Environment location: [Bare-metal]
  • Method of cuDF install: [from source]
@galipremsagar galipremsagar added bug Something isn't working python labels Aug 8, 2023
@galipremsagar galipremsagar self-assigned this Aug 8, 2023
rapids-bot bot pushed a commit that referenced this issue Aug 8, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant