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

Raise NotImplementedError for to_datetime with z format #14037

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions python/cudf/cudf/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,13 @@ def to_datetime(
if utc:
raise NotImplementedError("utc is not yet implemented")

if format is not None and "%f" in format:
format = format.replace("%f", "%9f")
if format is not None:
if "%Z" in format or "%z" in format:
raise NotImplementedError(
"cuDF does not yet support timezone-aware datetimes"
)
elif "%f" in format:
format = format.replace("%f", "%9f")
Comment on lines +151 to +156
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This is fine, but I'll just note that %%Z is a valid string for strptime that means "look for a literal %Z". So this replacement (and the existing %f replacement) is not robust against some of the wackier formats a user might provide.


try:
if isinstance(arg, cudf.DataFrame):
Expand Down
8 changes: 8 additions & 0 deletions python/cudf/cudf/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2148,3 +2148,11 @@ def test_daterange_pandas_compatibility():
"2010-01-01", "2010-02-01", periods=10, name="times"
)
assert_eq(expected, actual)


@pytest.mark.parametrize("code", ["z", "Z"])
def test_format_timezone_not_implemented(code):
with pytest.raises(NotImplementedError):
cudf.to_datetime(
["2020-01-01 00:00:00 UTC"], format=f"%Y-%m-%d %H-%M-%S %{code}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
["2020-01-01 00:00:00 UTC"], format=f"%Y-%m-%d %H-%M-%S %{code}"
["2020-01-01 00:00:00 UTC"], format=f"%Y-%m-%d %H:%M:%S %{code}"

Format string doesn't match the provided date string without it (and once timezones are implemented, we would expect this test to raise ValueError because of it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch

)
Loading