-
Notifications
You must be signed in to change notification settings - Fork 908
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add string.convert.convert_datetime/convert_booleans APIs to pylibcudf (
#16971) Contributes to #15162 Also address a review in #16935 (comment) This also modifies some `format` arguments in `convert_datetime.pyx` to accept `str` instead of `bytes` (`const string&`) to align more with Python. Let me know if you prefer to change this back Authors: - Matthew Roeschke (https://github.com/mroeschke) Approvers: - Vyas Ramasubramani (https://github.com/vyasr) URL: #16971
- Loading branch information
Showing
15 changed files
with
286 additions
and
116 deletions.
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
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,2 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
from . cimport convert_datetime, convert_durations | ||
from . cimport convert_booleans, convert_datetime, convert_durations |
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,2 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
from . import convert_datetime, convert_durations | ||
from . import convert_booleans, convert_datetime, convert_durations |
9 changes: 9 additions & 0 deletions
9
python/pylibcudf/pylibcudf/strings/convert/convert_booleans.pxd
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,9 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
from pylibcudf.column cimport Column | ||
from pylibcudf.scalar cimport Scalar | ||
|
||
|
||
cpdef Column to_booleans(Column input, Scalar true_string) | ||
|
||
cpdef Column from_booleans(Column booleans, Scalar true_string, Scalar false_string) |
91 changes: 91 additions & 0 deletions
91
python/pylibcudf/pylibcudf/strings/convert/convert_booleans.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,91 @@ | ||
# 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.scalar.scalar cimport string_scalar | ||
from pylibcudf.libcudf.strings.convert cimport ( | ||
convert_booleans as cpp_convert_booleans, | ||
) | ||
from pylibcudf.scalar cimport Scalar | ||
|
||
from cython.operator import dereference | ||
|
||
|
||
cpdef Column to_booleans(Column input, Scalar true_string): | ||
""" | ||
Returns a new bool column by parsing boolean values from the strings | ||
in the provided strings column. | ||
For details, see :cpp:func:`cudf::strings::to_booleans`. | ||
Parameters | ||
---------- | ||
input : Column | ||
Strings instance for this operation | ||
true_string : Scalar | ||
String to expect for true. Non-matching strings are false | ||
Returns | ||
------- | ||
Column | ||
New bool column converted from strings. | ||
""" | ||
cdef unique_ptr[column] c_result | ||
cdef const string_scalar* c_true_string = <const string_scalar*>( | ||
true_string.c_obj.get() | ||
) | ||
|
||
with nogil: | ||
c_result = move( | ||
cpp_convert_booleans.to_booleans( | ||
input.view(), | ||
dereference(c_true_string) | ||
) | ||
) | ||
|
||
return Column.from_libcudf(move(c_result)) | ||
|
||
cpdef Column from_booleans(Column booleans, Scalar true_string, Scalar false_string): | ||
""" | ||
Returns a new strings column converting the boolean values from the | ||
provided column into strings. | ||
For details, see :cpp:func:`cudf::strings::from_booleans`. | ||
Parameters | ||
---------- | ||
booleans : Column | ||
Boolean column to convert. | ||
true_string : Scalar | ||
String to use for true in the output column. | ||
false_string : Scalar | ||
String to use for false in the output column. | ||
Returns | ||
------- | ||
Column | ||
New strings column. | ||
""" | ||
cdef unique_ptr[column] c_result | ||
cdef const string_scalar* c_true_string = <const string_scalar*>( | ||
true_string.c_obj.get() | ||
) | ||
cdef const string_scalar* c_false_string = <const string_scalar*>( | ||
false_string.c_obj.get() | ||
) | ||
|
||
with nogil: | ||
c_result = move( | ||
cpp_convert_booleans.from_booleans( | ||
booleans.view(), | ||
dereference(c_true_string), | ||
dereference(c_false_string), | ||
) | ||
) | ||
|
||
return Column.from_libcudf(move(c_result)) |
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
Oops, something went wrong.