-
Notifications
You must be signed in to change notification settings - Fork 913
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 string.convert.convert_urls APIs to pylibcudf #17003
Merged
rapids-bot
merged 2 commits into
rapidsai:branch-24.12
from
mroeschke:pylibcudf/strings/convert_urls
Oct 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
from . cimport convert_booleans, convert_datetime, convert_durations | ||
from . cimport ( | ||
convert_booleans, | ||
convert_datetime, | ||
convert_durations, | ||
convert_urls, | ||
) |
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
from . import convert_booleans, convert_datetime, convert_durations | ||
from . import ( | ||
convert_booleans, | ||
convert_datetime, | ||
convert_durations, | ||
convert_urls, | ||
) |
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,8 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
from pylibcudf.column cimport Column | ||
|
||
|
||
cpdef Column url_encode(Column Input) | ||
|
||
cpdef Column url_decode(Column Input) |
63 changes: 63 additions & 0 deletions
63
python/pylibcudf/pylibcudf/strings/convert/convert_urls.pyx
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,63 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
from libcpp.memory cimport unique_ptr | ||
from libcpp.utility cimport move | ||
from pylibcudf.column cimport Column | ||
from pylibcudf.libcudf.column.column cimport column | ||
from pylibcudf.libcudf.strings.convert cimport convert_urls as cpp_convert_urls | ||
|
||
|
||
cpdef Column url_encode(Column input): | ||
""" | ||
Encodes each string using URL encoding. | ||
|
||
For details, see :cpp:func:`cudf::strings::url_encode` | ||
|
||
Parameters | ||
---------- | ||
input : Column | ||
Strings instance for this operation. | ||
|
||
Returns | ||
------- | ||
Column | ||
New strings column. | ||
""" | ||
cdef unique_ptr[column] c_result | ||
|
||
with nogil: | ||
c_result = move( | ||
cpp_convert_urls.url_encode( | ||
input.view() | ||
) | ||
) | ||
|
||
return Column.from_libcudf(move(c_result)) | ||
|
||
|
||
cpdef Column url_decode(Column input): | ||
""" | ||
Decodes each string using URL encoding. | ||
|
||
For details, see :cpp:func:`cudf::strings::url_decode` | ||
|
||
Parameters | ||
---------- | ||
input : Column | ||
Strings instance for this operation. | ||
|
||
Returns | ||
------- | ||
Column | ||
New strings column. | ||
""" | ||
cdef unique_ptr[column] c_result | ||
|
||
with nogil: | ||
c_result = move( | ||
cpp_convert_urls.url_decode( | ||
input.view() | ||
) | ||
) | ||
|
||
return Column.from_libcudf(move(c_result)) |
36 changes: 36 additions & 0 deletions
36
python/pylibcudf/pylibcudf/tests/test_string_convert_urls.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,36 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
import urllib | ||
|
||
import pyarrow as pa | ||
import pylibcudf as plc | ||
from utils import assert_column_eq | ||
|
||
|
||
def test_url_encode(): | ||
data = ["/home/nfs", None] | ||
arr = pa.array(data) | ||
result = plc.strings.convert.convert_urls.url_encode( | ||
plc.interop.from_arrow(arr) | ||
) | ||
expected = pa.array( | ||
[ | ||
urllib.parse.quote(url, safe="") if isinstance(url, str) else url | ||
for url in data | ||
] | ||
) | ||
assert_column_eq(result, expected) | ||
|
||
|
||
def test_url_decode(): | ||
data = ["%2Fhome%2fnfs", None] | ||
arr = pa.array(data) | ||
result = plc.strings.convert.convert_urls.url_decode( | ||
plc.interop.from_arrow(arr) | ||
) | ||
expected = pa.array( | ||
[ | ||
urllib.parse.unquote(url) if isinstance(url, str) else url | ||
for url in data | ||
] | ||
) | ||
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.
@vyasr should we be marking these APIs all with
libcudf_exception_handler
as we go even if currently the API has no documented exception cases?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.
I think that's probably a good best practice yeah.
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.
xref #17036 to follow up in the future