-
Notifications
You must be signed in to change notification settings - Fork 912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docstrings and test for strings.convert_durations APIs for pylibcudf #16982
Merged
rapids-bot
merged 5 commits into
rapidsai:branch-24.12
from
mroeschke:pylibcudf/strings/convert2
Oct 4, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
70cff6f
Add docstrings and test for strings.convert_durations APIs for pylibcudf
mroeschke cb6b316
Update python/pylibcudf/pylibcudf/tests/test_string_convert_durations.py
mroeschke c9043db
Update python/pylibcudf/pylibcudf/tests/test_string_convert_durations.py
mroeschke 8c003fc
Update python/pylibcudf/pylibcudf/strings/convert/convert_durations.pyx
mroeschke 11a5540
Update python/pylibcudf/pylibcudf/tests/test_string_convert_durations.py
mroeschke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
python/pylibcudf/pylibcudf/tests/test_string_convert_durations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
from datetime import datetime, timedelta | ||
|
||
import pyarrow as pa | ||
import pylibcudf as plc | ||
import pytest | ||
from utils import assert_column_eq | ||
|
||
|
||
@pytest.fixture( | ||
params=[ | ||
pa.duration("ns"), | ||
pa.duration("us"), | ||
pa.duration("ms"), | ||
pa.duration("s"), | ||
], | ||
) | ||
def duration_type(request): | ||
return request.param | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def pa_duration_col(): | ||
return pa.array(["05:20:25"]) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def plc_duration_col(pa_duration_col): | ||
return plc.interop.from_arrow(pa_duration_col) | ||
|
||
|
||
def test_to_duration(pa_duration_col, plc_duration_col, duration_type): | ||
format = "%H:%M:%S" | ||
|
||
def to_timedelta(duration_str): | ||
date = datetime.strptime(duration_str, format) | ||
return date - datetime(1900, 1, 1) # "%H:%M:%S" zero date | ||
|
||
expect = pa.array([to_timedelta(d.as_py()) for d in pa_duration_col]).cast( | ||
duration_type | ||
) | ||
|
||
got = plc.strings.convert.convert_durations.to_durations( | ||
plc_duration_col, | ||
plc.interop.from_arrow(duration_type), | ||
format, | ||
) | ||
assert_column_eq(expect, got) | ||
|
||
|
||
@pytest.mark.parametrize("format", [None, "%D days %H:%M:%S"]) | ||
def test_from_durations(format): | ||
pa_array = pa.array( | ||
[timedelta(days=1, hours=1, minutes=1, seconds=1), None] | ||
) | ||
result = plc.strings.convert.convert_durations.from_durations( | ||
plc.interop.from_arrow(pa_array), format | ||
) | ||
expected = pa.array(["1 days 01:01:01", None]) | ||
assert_column_eq(result, expected) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, sorry we missed this on review.