diff --git a/python/cudf/cudf/core/tools/datetimes.py b/python/cudf/cudf/core/tools/datetimes.py index 7c4b9810df2..a759f9dc3e1 100644 --- a/python/cudf/cudf/core/tools/datetimes.py +++ b/python/cudf/cudf/core/tools/datetimes.py @@ -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") try: if isinstance(arg, cudf.DataFrame): diff --git a/python/cudf/cudf/tests/test_datetime.py b/python/cudf/cudf/tests/test_datetime.py index b1685950241..4a4e9b67c2e 100644 --- a/python/cudf/cudf/tests/test_datetime.py +++ b/python/cudf/cudf/tests/test_datetime.py @@ -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}" + )