-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python bindings for
get_json_object
(#7981)
Fixes: [7916](#7916) Authors: - Sheilah Kirui (https://github.com/skirui-source) Approvers: - Keith Kraus (https://github.com/kkraus14) URL: #7981
- Loading branch information
1 parent
96c0706
commit 8ae73d5
Showing
4 changed files
with
259 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) 2021, NVIDIA CORPORATION. | ||
|
||
from cudf._lib.cpp.column.column_view cimport column_view | ||
from cudf._lib.cpp.scalar.scalar cimport string_scalar | ||
from libcpp.memory cimport unique_ptr | ||
from libcpp.string cimport string | ||
|
||
from cudf._lib.cpp.column.column cimport column | ||
from cudf._lib.cpp.scalar.scalar cimport scalar | ||
|
||
|
||
cdef extern from "cudf/strings/json.hpp" namespace "cudf::strings" nogil: | ||
cdef unique_ptr[column] get_json_object( | ||
column_view col, | ||
string_scalar json_path, | ||
) except + |
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) 2021, NVIDIA CORPORATION. | ||
|
||
from libcpp.memory cimport unique_ptr | ||
from libcpp.utility cimport move | ||
from cudf._lib.cpp.column.column_view cimport column_view | ||
from cudf._lib.cpp.scalar.scalar cimport string_scalar | ||
from cudf._lib.cpp.types cimport size_type | ||
from cudf._lib.column cimport Column | ||
from cudf._lib.scalar cimport DeviceScalar | ||
from cudf._lib.cpp.column.column cimport column | ||
|
||
from cudf._lib.cpp.strings.json cimport ( | ||
get_json_object as cpp_get_json_object | ||
) | ||
|
||
|
||
def get_json_object(Column col, object py_json_path): | ||
""" | ||
Apply a JSONPath string to all rows in an input column | ||
of json strings. | ||
""" | ||
cdef unique_ptr[column] c_result | ||
|
||
cdef column_view col_view = col.view() | ||
cdef DeviceScalar json_path = py_json_path.device_value | ||
|
||
cdef const string_scalar* scalar_json_path = <const string_scalar*>( | ||
json_path.get_raw_ptr() | ||
) | ||
with nogil: | ||
c_result = move(cpp_get_json_object( | ||
col_view, | ||
scalar_json_path[0], | ||
)) | ||
|
||
return Column.from_unique_ptr(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
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