Skip to content

Commit

Permalink
Change default datetime index resolution to ns to match pandas (this …
Browse files Browse the repository at this point in the history
…is a breaking change).
  • Loading branch information
vyasr committed Jun 25, 2021
1 parent 0c64d0d commit acb536e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 10 additions & 1 deletion python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,15 @@ def __init__(
if yearfirst is not False:
raise NotImplementedError("yearfirst == True is not yet supported")

valid_dtypes = tuple(
f"datetime64[{res}]" for res in ("s", "ms", "us", "ns")
)
if dtype is None:
# nanosecond default matches pandas
dtype = "datetime64[ns]"
elif dtype not in valid_dtypes:
raise TypeError("Invalid dtype")

if copy:
data = column.as_column(data).copy()
kwargs = _setdefault_name(data, name=name)
Expand All @@ -2131,7 +2140,7 @@ def __init__(
elif isinstance(data, pd.DatetimeIndex):
data = column.as_column(data.values)
elif isinstance(data, (list, tuple)):
data = column.as_column(np.array(data, dtype="datetime64[ms]"))
data = column.as_column(np.array(data, dtype=dtype))
super().__init__(data, **kwargs)

@property
Expand Down
3 changes: 0 additions & 3 deletions python/cudf/cudf/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,6 @@ def test_index_copy_datetime(name, dtype, deep=True):
pidx_copy = pidx.copy(name=name, deep=deep, dtype=dtype)
cidx_copy = cidx.copy(name=name, deep=deep, dtype=dtype)

# By default, cudf.DatetimeIndex uses [ms] as base unit, pandas uses [ns]
if dtype == "int64":
cidx_copy = cidx_copy * 1000000
assert_eq(pidx_copy, cidx_copy)


Expand Down

0 comments on commit acb536e

Please sign in to comment.