Skip to content

Commit

Permalink
Add validation for errors parameter in cudf.to_datetime (#8068)
Browse files Browse the repository at this point in the history
This PR checks for the parameter being passed to `errors` in `cudf.to_datetime`.

This PR only partially addresses #8010

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Ram (Ramakrishna Prabhu) (https://github.com/rgsl888prabhu)

URL: #8068
  • Loading branch information
galipremsagar authored Apr 27, 2021
1 parent 9b2e456 commit 1a0d304
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/cudf/cudf/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions python/cudf/cudf/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
)

0 comments on commit 1a0d304

Please sign in to comment.