diff --git a/python/cudf/cudf/core/column/datetime.py b/python/cudf/cudf/core/column/datetime.py index 7980b58ab8b..466ea3220c8 100644 --- a/python/cudf/cudf/core/column/datetime.py +++ b/python/cudf/cudf/core/column/datetime.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2023, NVIDIA CORPORATION. +# Copyright (c) 2019-2024, NVIDIA CORPORATION. from __future__ import annotations @@ -102,6 +102,9 @@ def infer_format(element: str, **kwargs) -> str: """ Infers datetime format from a string, also takes cares for `ms` and `ns` """ + if not cudf.get_option("mode.pandas_compatible"): + # We allow "Z" but don't localize it to datetime64[ns, UTC] type (yet) + element = element.replace("Z", "") fmt = _guess_datetime_format(element, **kwargs) if fmt is not None: diff --git a/python/cudf/cudf/tests/test_datetime.py b/python/cudf/cudf/tests/test_datetime.py index 07c8c407ab9..22d452fdda5 100644 --- a/python/cudf/cudf/tests/test_datetime.py +++ b/python/cudf/cudf/tests/test_datetime.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2023, NVIDIA CORPORATION. +# Copyright (c) 2019-2024, NVIDIA CORPORATION. import datetime import operator @@ -1306,8 +1306,10 @@ def test_datetime_infer_format(data, timezone, dtype): assert_eq(expected, actual) else: - with pytest.raises(NotImplementedError): - sr.astype(dtype) + with cudf.option_context("mode.pandas_compatible", True): + with pytest.raises(NotImplementedError): + # pandas doesn't allow parsing "Z" to naive type + sr.astype(dtype) def test_dateoffset_instance_subclass_check(): @@ -2308,12 +2310,22 @@ def test_format_timezone_not_implemented(code): ) -@pytest.mark.parametrize("tz", ["Z", "UTC-3", "+01:00"]) -def test_no_format_timezone_not_implemented(tz): +@pytest.mark.parametrize("tz", ["UTC-3", "+01:00"]) +def test_utc_offset_not_implemented(tz): with pytest.raises(NotImplementedError): cudf.to_datetime([f"2020-01-01 00:00:00{tz}"]) +def test_Z_utc_offset(): + with cudf.option_context("mode.pandas_compatible", True): + with pytest.raises(NotImplementedError): + cudf.to_datetime(["2020-01-01 00:00:00Z"]) + + result = cudf.to_datetime(["2020-01-01 00:00:00Z"]) + expected = cudf.to_datetime(["2020-01-01 00:00:00"]) + assert_eq(result, expected) + + @pytest.mark.parametrize("arg", [True, False]) def test_args_not_datetime_typerror(arg): with pytest.raises(TypeError):