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

Conversation

mroeschke
Copy link
Contributor

@mroeschke mroeschke commented Sep 6, 2023

Description

Avoids timezone information from being dropped in to_datetime when the z directive is provided

In [1]: import cudf

In [2]: fmt = '%Y-%m-%d %H:%M:%S %Z'
   ...: dates = ['2010-01-01 12:00:00 UTC', '2010-01-01 12:00:00 UTC']

In [3]: cudf.to_datetime(dates, format=fmt)
Out[3]: DatetimeIndex(['2010-01-01 12:00:00', '2010-01-01 12:00:00'], dtype='datetime64[ns]')

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@mroeschke mroeschke added bug Something isn't working non-breaking Non-breaking change labels Sep 6, 2023
@mroeschke mroeschke requested a review from a team as a code owner September 6, 2023 02:04
@mroeschke mroeschke requested review from shwina and isVoid September 6, 2023 02:04
@github-actions github-actions bot added the Python Affects Python cuDF API. label Sep 6, 2023
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

Comment on lines +151 to +156
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")
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.

Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

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

Thanks @mroeschke

@mroeschke
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit ea59dbf into rapidsai:branch-23.10 Sep 6, 2023
54 checks passed
@mroeschke mroeschke deleted the bug/datetime/z branch September 6, 2023 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants