Skip to content

Commit

Permalink
Allowing %f in format to return nanoseconds (#9081)
Browse files Browse the repository at this point in the history
This is a quick fix to close PR #7945 
This PR checks to see if `%f` is passed as part of `format`  into `cudf.to_datetime`. Previously, cudf would not return nanoseconds, while pandas does.

Authors:
  - Marlene  (https://github.com/marlenezw)

Approvers:
  - Ashwin Srinath (https://github.com/shwina)

URL: #9081
  • Loading branch information
marlenezw authored Aug 23, 2021
1 parent 332dedf commit 406e87b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/cudf/cudf/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def to_datetime(
if yearfirst:
raise NotImplementedError("yearfirst support is not yet implemented")

if format is not None and "%f" in format:
format = format.replace("%f", "%9f")

try:
if isinstance(arg, cudf.DataFrame):
# we require at least Ymd
Expand Down
1 change: 1 addition & 0 deletions python/cudf/cudf/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ def test_to_datetime_units(data, unit):
(["10/11/2012", "01/01/2010", "07/07/2016", "02/02/2014"], "%m/%d/%Y"),
(["10/11/2012", "01/01/2010", "07/07/2016", "02/02/2014"], "%d/%m/%Y"),
(["10/11/2012", "01/01/2010", "07/07/2016", "02/02/2014"], None),
(["2021-04-13 12:30:04.123456789"], "%Y-%m-%d %H:%M:%S.%f"),
(pd.Series([2015, 2020, 2021]), "%Y"),
pytest.param(
pd.Series(["1", "2", "1"]),
Expand Down

0 comments on commit 406e87b

Please sign in to comment.