diff --git a/python/cudf/cudf/core/tools/datetimes.py b/python/cudf/cudf/core/tools/datetimes.py index 5e74e5bfebf..816de4faf53 100644 --- a/python/cudf/cudf/core/tools/datetimes.py +++ b/python/cudf/cudf/core/tools/datetimes.py @@ -104,6 +104,13 @@ def to_datetime( >>> cudf.to_datetime(1490195805433502912, unit='ns') numpy.datetime64('1780-11-20T01:02:30.494253056') """ + if errors not in {"ignore", "raise", "coerce", "warn"}: + raise ValueError( + f"errors parameter has to be either one of: " + f"{['ignore', 'raise', 'coerce', 'warn']}, found: " + f"{errors}" + ) + if arg is None: return None diff --git a/python/cudf/cudf/tests/test_datetime.py b/python/cudf/cudf/tests/test_datetime.py index 7eb8fcd0aa4..647ff5250ba 100644 --- a/python/cudf/cudf/tests/test_datetime.py +++ b/python/cudf/cudf/tests/test_datetime.py @@ -1248,3 +1248,17 @@ def test_datetime_infer_format(data, dtype): def test_dateoffset_instance_subclass_check(): assert not issubclass(pd.DateOffset, cudf.DateOffset) assert not isinstance(pd.DateOffset(), cudf.DateOffset) + + +def test_datetime_to_datetime_error(): + assert_exceptions_equal( + lfunc=pd.to_datetime, + rfunc=cudf.to_datetime, + lfunc_args_and_kwargs=(["02-Oct-2017 09:30", "%d-%B-%Y %H:%M"],), + rfunc_args_and_kwargs=(["02-Oct-2017 09:30", "%d-%B-%Y %H:%M"],), + check_exception_type=False, + expected_error_message=re.escape( + "errors parameter has to be either one of: ['ignore', 'raise', " + "'coerce', 'warn'], found: %d-%B-%Y %H:%M" + ), + )