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

Change default datetime index resolution to ns to match pandas #8611

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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