Skip to content
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 read-only functions on string dtypes to DataFrame.apply and Series.apply #11319

Merged
merged 245 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
245 commits
Select commit Hold shift + click to select a range
84592ee
plumbed but returning zeros
brandon-b-miller Feb 3, 2022
f18f03a
up and running
brandon-b-miller Feb 4, 2022
0921c8f
move code around
brandon-b-miller Feb 10, 2022
2aa6299
remove old file
brandon-b-miller Feb 10, 2022
38a1c44
bugfixes and a temporary workaround
brandon-b-miller Feb 11, 2022
b7d6ba2
Merge branch 'branch-22.04' into string_udfs
brandon-b-miller Feb 15, 2022
2d0b505
successfully casting literal->masked string
brandon-b-miller Feb 23, 2022
a3e0b7f
startswith lowering
brandon-b-miller Feb 23, 2022
2dc33f7
Merge branch 'branch-22.04' into string_udfs
brandon-b-miller Feb 28, 2022
087a9f2
fix bugs in startswith, which now works
brandon-b-miller Feb 28, 2022
2930e75
add typing and lowering for ends_with
brandon-b-miller Mar 8, 2022
f190d43
implement rfind
brandon-b-miller Mar 8, 2022
b056f41
add some basic testing
brandon-b-miller Mar 8, 2022
06596c0
fix bug
brandon-b-miller Mar 8, 2022
ad983f8
run black
brandon-b-miller Mar 8, 2022
9eda436
adjust and document StringViewArgHandler
brandon-b-miller Mar 9, 2022
bd56aaa
adjust doc
brandon-b-miller Mar 9, 2022
d12b6da
move things around
brandon-b-miller Mar 9, 2022
f2a72f0
improvements to struct modeling logic
brandon-b-miller Mar 9, 2022
426820f
fix caching issue
brandon-b-miller Mar 9, 2022
132e6b8
struct size is only 16?
brandon-b-miller Mar 9, 2022
22ce467
minor update
brandon-b-miller Mar 9, 2022
92df351
merge latest
brandon-b-miller Apr 6, 2022
c6fbdcf
fix bug introduced by bad merge
brandon-b-miller Apr 6, 2022
1e9dec3
partial implementation for returning strings
brandon-b-miller Apr 6, 2022
dd416a2
returning a string is working
brandon-b-miller Apr 8, 2022
0ebcd07
remove stale breakpoint
brandon-b-miller Apr 8, 2022
297070a
a wrong and not working, but informative attempt at upper()
brandon-b-miller Apr 11, 2022
e3456de
returning dstrings instead of string_views
brandon-b-miller Apr 11, 2022
55abe5e
fully convert to dstring
brandon-b-miller Apr 12, 2022
1dbd427
tests and plumbing for upper
brandon-b-miller Apr 12, 2022
f030f90
plumbed lower
brandon-b-miller Apr 12, 2022
c05bd6d
merge latest
brandon-b-miller Apr 13, 2022
4c95fc3
partial getitem implementation for ints, not working yet
brandon-b-miller Apr 13, 2022
f09eceb
substring plumbing, also not working (for the same reason as at)
brandon-b-miller Apr 13, 2022
b0fb8d2
substr RUNNING but different results from pandas...
brandon-b-miller Apr 14, 2022
3691c89
add strip, rstrip, and lstrip
brandon-b-miller Apr 14, 2022
66e92e2
working through +, not working yet
brandon-b-miller Apr 18, 2022
b1a8588
Merge branch 'branch-22.06' into string_udfs
brandon-b-miller May 13, 2022
1cf26a4
plumb out to stringudfs
brandon-b-miller May 23, 2022
e61815d
plumbing startswith and endswith back in
brandon-b-miller May 26, 2022
47b07e8
Merge branch 'branch-22.08' into string_udfs
brandon-b-miller May 31, 2022
19f491a
updates from strings_udf/main
brandon-b-miller Jun 15, 2022
adad2bd
Merge branch 'branch-22.08' into string_udfs
brandon-b-miller Jul 6, 2022
9897a2b
Merge branch 'branch-22.08' into string_udfs
brandon-b-miller Jul 12, 2022
bca8fe8
plumb back in several more functions
brandon-b-miller Jul 12, 2022
f165547
support comparison operators between strings. Reuses existing lowering?
brandon-b-miller Jul 14, 2022
551150e
Merge branch 'branch-22.08' into string_udfs
brandon-b-miller Jul 19, 2022
a232a20
first attempt at adding strings_udf as a subpackage
brandon-b-miller Jul 19, 2022
f9f0ac2
add other _is_ functions
brandon-b-miller Jul 20, 2022
35d238b
updates
brandon-b-miller Jul 20, 2022
cc661b3
strings_udf lowering shall not import cudf, and functions shall be at…
brandon-b-miller Jul 21, 2022
3710d9b
Fix style checks for string_udfs.
bdice Jul 21, 2022
5602da8
Merge pull request #1 from bdice/string_udfs-style
brandon-b-miller Jul 22, 2022
c0d212c
Merge branch 'branch-22.08' into string_udfs
brandon-b-miller Jul 22, 2022
2442bf2
configure strings_udf to be optional based on a runtime check
brandon-b-miller Jul 27, 2022
0b35e16
remove stake breakpoint
brandon-b-miller Jul 27, 2022
2a010f4
skip string tests if not enabled
brandon-b-miller Aug 1, 2022
8bd7773
add a build script
brandon-b-miller Aug 1, 2022
92229b7
add build script to main build script
brandon-b-miller Aug 1, 2022
6058a2b
merge latest
brandon-b-miller Aug 1, 2022
1d868b4
pass style checks, move functions to lowering
brandon-b-miller Aug 2, 2022
df05054
Merge branch 'branch-22.10' into string_udfs
brandon-b-miller Aug 3, 2022
c8aa6f8
more wrangling with style checks, somehow
brandon-b-miller Aug 3, 2022
8635f28
last try
brandon-b-miller Aug 3, 2022
d208c5b
Fix isort.
bdice Aug 3, 2022
022f820
Merge pull request #2 from bdice/isort-fix
brandon-b-miller Aug 3, 2022
60e60be
Proposed isort changes.
bdice Aug 3, 2022
05fefbd
Merge pull request #3 from bdice/isort-fix
brandon-b-miller Aug 3, 2022
fb3820f
allow import on CPU only machine
brandon-b-miller Aug 3, 2022
eed2a52
catch importerror
brandon-b-miller Aug 3, 2022
8d4d10b
updates
brandon-b-miller Aug 3, 2022
099a1fc
do not import stringview in masked constructor
brandon-b-miller Aug 3, 2022
26be2a0
start adding strings_udf to ci test scripts
brandon-b-miller Aug 3, 2022
6df94b7
excize string udf imports in masked typing
brandon-b-miller Aug 4, 2022
8ac7455
excise string_udf imports from row_function.py
brandon-b-miller Aug 4, 2022
77d19b1
remove license
brandon-b-miller Aug 5, 2022
6095fa9
Merge branch 'branch-22.10' into string_udfs
brandon-b-miller Aug 8, 2022
938f017
begin adding and testing conda package
brandon-b-miller Aug 8, 2022
4119b6d
conda and build updates
brandon-b-miller Aug 9, 2022
d6e043b
add cython to meta.yaml
brandon-b-miller Aug 9, 2022
2cbf750
try yaml from cudf
brandon-b-miller Aug 9, 2022
53dd3f6
add conda_build_config.yaml
brandon-b-miller Aug 9, 2022
436f16f
use skbuild
brandon-b-miller Aug 10, 2022
293652d
update meta.yaml
brandon-b-miller Aug 10, 2022
43a11aa
build using build system independent commands
brandon-b-miller Aug 11, 2022
2733360
change around cuda version constraints, adjust cmake to ship ptx hope…
brandon-b-miller Aug 15, 2022
501cabb
Merge branch 'branch-22.10' into string_udfs
brandon-b-miller Aug 15, 2022
4273949
prune out dstring until phase 2 and CLI files for now
brandon-b-miller Aug 16, 2022
196f0dd
add back mistakenly removed udf_apis.hpp, which is required
brandon-b-miller Aug 16, 2022
241fd3b
add back in just the needed parts of udf_apis, resolve cython errors
brandon-b-miller Aug 16, 2022
0912904
Merge branch 'branch-22.10' into string_udfs
brandon-b-miller Aug 17, 2022
71e5cab
fix _get_frame_row_type struct alignment issues
brandon-b-miller Aug 17, 2022
24d6022
move PTX to conda prefix
brandon-b-miller Aug 17, 2022
996d944
minor update
brandon-b-miller Aug 17, 2022
2b669de
create skbuild process based on the one from cudf
brandon-b-miller Aug 19, 2022
8324831
run pre-commit
brandon-b-miller Aug 19, 2022
08904f7
install versioneer into subpackage
brandon-b-miller Aug 22, 2022
7e985d3
ignore versioneer in all subpackages
brandon-b-miller Aug 22, 2022
1406d88
link to libcudf_strings_udf during cython build
brandon-b-miller Aug 22, 2022
29bc117
small fixes
brandon-b-miller Aug 22, 2022
2aafe03
update properties of setup.cfg and rerun pre-commit
brandon-b-miller Aug 22, 2022
d2bc899
pyarrow 8->9 in meta.yaml
brandon-b-miller Aug 22, 2022
1a5341a
updates from local CI testing
brandon-b-miller Aug 24, 2022
b293eb6
simplify setup.py
brandon-b-miller Aug 24, 2022
7df7172
no need to rebuild strings_udf on test nodes, just install from packa…
brandon-b-miller Aug 30, 2022
475f62a
build strings_udf conda package on cpu_build jobs
brandon-b-miller Aug 30, 2022
0460abc
build both 3.8 and 3.9 conda packages on CPU only, and add debugging …
brandon-b-miller Aug 31, 2022
1b307b9
restrict strings_udf based on version of CUDA originally used to comp…
brandon-b-miller Aug 31, 2022
d847ad8
merge and resolve conflicts
brandon-b-miller Sep 2, 2022
67bb0a7
small cleanups
brandon-b-miller Sep 2, 2022
b9acab9
prune files and update to strings_udf repo
brandon-b-miller Sep 2, 2022
3852d79
format c++ files
brandon-b-miller Sep 2, 2022
30b1a45
Update python/strings_udf/cpp/include/cudf/strings/udf/char_types.cuh
davidwendt Sep 2, 2022
6a51daa
Apply suggestions from code review
brandon-b-miller Sep 6, 2022
fe1cddc
address reviews
brandon-b-miller Sep 6, 2022
8b2c1e7
merge test files
brandon-b-miller Sep 6, 2022
f19ead6
Apply suggestions from code review
brandon-b-miller Sep 7, 2022
b3eeb9f
prune cython files
brandon-b-miller Sep 7, 2022
c4b4c7b
prune imports and correct use of gil
brandon-b-miller Sep 7, 2022
9231469
define size_type = types.int32 and use throughout strings_udf and cud…
brandon-b-miller Sep 7, 2022
985572f
move functions around in tests/utils.py
brandon-b-miller Sep 7, 2022
bfcb0ec
add tests and bindings for MaskedType(string_view).count()
brandon-b-miller Sep 7, 2022
7958150
move .clang-format to repo root
brandon-b-miller Sep 7, 2022
1183e8c
search for cuda version using re
brandon-b-miller Sep 7, 2022
6e152ff
Apply suggestions from code review
brandon-b-miller Sep 8, 2022
66cbc3d
address reviews
brandon-b-miller Sep 8, 2022
b99ddd6
Update count() logic
davidwendt Sep 8, 2022
11a35d7
add more parenthesis
davidwendt Sep 9, 2022
1f78b05
remove blank line
davidwendt Sep 9, 2022
0d3f761
include install guard in build.sh
brandon-b-miller Sep 9, 2022
c3e174c
revert changes to update-version.sh
brandon-b-miller Sep 9, 2022
2bca928
prune meta.yaml
brandon-b-miller Sep 9, 2022
35e159e
delete strings_udf from namespace if not enabled
brandon-b-miller Sep 9, 2022
25c4a7c
Apply suggestions from code review
brandon-b-miller Sep 9, 2022
e799232
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
brandon-b-miller Sep 9, 2022
99b7f3b
use a decorator to create lowerings dynamically
brandon-b-miller Sep 9, 2022
c44c575
dynamically generate typing
brandon-b-miller Sep 9, 2022
cf118e9
renaming
brandon-b-miller Sep 9, 2022
54a0013
Update python/strings_udf/strings_udf/_lib/cudf_jit_udf.pyx
brandon-b-miller Sep 9, 2022
c3f1968
clean tables.pyx
brandon-b-miller Sep 9, 2022
2dc437b
relink imports from strings_udf library
brandon-b-miller Sep 9, 2022
a64a745
dynamically generate attributes of MaskedType(string_view)
brandon-b-miller Sep 9, 2022
8938f1b
dynamically generated lowerings for MaskedType(string_view)
brandon-b-miller Sep 9, 2022
c4438c5
simplify test suite using fixtures
brandon-b-miller Sep 9, 2022
1faf49d
use a fixture in test_string_udfs
brandon-b-miller Sep 9, 2022
c0bd0f5
remove comments in shim.cu
brandon-b-miller Sep 9, 2022
80b176e
prune setup.py
brandon-b-miller Sep 9, 2022
67fada7
address reviews in __init__.py
brandon-b-miller Sep 9, 2022
45396fb
more __init__ updates
brandon-b-miller Sep 9, 2022
7489e7f
update test utils in strings_udf library
brandon-b-miller Sep 9, 2022
49db996
merge test utils into test_string_udfs.py
brandon-b-miller Sep 9, 2022
95b6f5e
Change C++ strings_udf code to be built as part of the Python code.
vyasr Sep 9, 2022
6272327
Simplify CUDA handling.
vyasr Sep 9, 2022
d003e85
Reorganize to clearly separate the C++ functionality from the shim code.
vyasr Sep 9, 2022
cc01707
Install the C++ lib.
vyasr Sep 9, 2022
10f3379
Compile shims for every architecture.
vyasr Sep 9, 2022
d204a06
Minor cleanup.
vyasr Sep 9, 2022
6416d9d
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
vyasr Sep 9, 2022
3a9be14
remove cpp build step from build.sh
brandon-b-miller Sep 10, 2022
8189f71
Remove unnecessary files.
vyasr Sep 10, 2022
138dd9a
Define some more fixtures.
vyasr Sep 10, 2022
9eb3bfd
Simplify binary func lowering.
vyasr Sep 10, 2022
f0d3c90
Pass signature params directly.
vyasr Sep 10, 2022
2bce019
Define alias for CPointer to string_view.
vyasr Sep 10, 2022
5fa1ccd
Some more boilerplate reduction.
vyasr Sep 10, 2022
3db5b91
Remove one more unnecessary file.
vyasr Sep 10, 2022
acadf53
Remove extra new line.
vyasr Sep 10, 2022
c945aa1
Minor CMake cleanup.
vyasr Sep 10, 2022
a8b6cf4
update copyright
davidwendt Sep 12, 2022
17598d6
fix small bugs in cuda function declarations
brandon-b-miller Sep 12, 2022
7c55deb
rework __init__ such that a CPU machine may import strings_udf
brandon-b-miller Sep 12, 2022
02f93d4
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
brandon-b-miller Sep 12, 2022
5ab660d
Fix return calculation for zero-length target in count()
davidwendt Sep 12, 2022
6f67b69
find and rfind return size_type
brandon-b-miller Sep 12, 2022
3be55cb
add ptx files in the strings_udf directory to .gitignore
brandon-b-miller Sep 12, 2022
b6f3482
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
brandon-b-miller Sep 12, 2022
9aaea65
Fix style check
davidwendt Sep 12, 2022
4ed60fb
pass rather than raise if no strings_udf
brandon-b-miller Sep 12, 2022
dfd819e
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
brandon-b-miller Sep 12, 2022
3acc721
skip strings_udf tests in library if not enabled
brandon-b-miller Sep 12, 2022
b70e5a0
debug print to find why files are not being found
brandon-b-miller Sep 12, 2022
325abb6
Run tests from inside the strings_udf directory.
vyasr Sep 12, 2022
e145105
Remove __init__ file that could be causing file traversal.
vyasr Sep 12, 2022
12abaf0
Add extra debug print.
vyasr Sep 12, 2022
3fbc85b
Clean up debug prints and remove unused patch_needed import.
vyasr Sep 13, 2022
52e686c
only add object to types if strings_udf is enabled
brandon-b-miller Sep 13, 2022
6fbb0d4
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
brandon-b-miller Sep 13, 2022
faf4878
add strings_udf to cudf conda recipe
brandon-b-miller Sep 13, 2022
36f41f6
cleanup
brandon-b-miller Sep 13, 2022
7ac5b7e
Remove cudf from strings_udf requirements.
vyasr Sep 13, 2022
6549668
go back to an optional dependency
brandon-b-miller Sep 13, 2022
a7afe7a
fix yaml error
brandon-b-miller Sep 13, 2022
69813de
dont directly import ptxpath in tests
brandon-b-miller Sep 13, 2022
18bd4bc
Enable flake8 again.
vyasr Sep 13, 2022
c71c2dd
Don't return a nonzero exit status when strings_udf tests are all ski…
vyasr Sep 13, 2022
5b585c7
Simplify declaration of lowering functions.
vyasr Sep 13, 2022
b86d44e
retest with strings_udf after initial tests
brandon-b-miller Sep 13, 2022
dadbaa4
Use more fixtures for the test.
vyasr Sep 13, 2022
243aa7a
Minor CMake cleanup.
vyasr Sep 13, 2022
5514b3e
Typo fixes.
vyasr Sep 13, 2022
713f23d
Switch prefix with postfix.
vyasr Sep 13, 2022
f324ebc
Some copyright fixes.
vyasr Sep 13, 2022
313757c
Remove unnecessary cmdclass modification.
vyasr Sep 13, 2022
fd1041a
Improve PTX file handling and error cases.
vyasr Sep 13, 2022
0e177de
Fix issue with rapids-cmake changing the variable name.
vyasr Sep 13, 2022
267c5af
More copyright fixes.
vyasr Sep 13, 2022
5bb80ff
Remove unnecessary temp variable.
vyasr Sep 13, 2022
a16a83d
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
vyasr Sep 13, 2022
b30ca2f
Add missing @param
davidwendt Sep 13, 2022
7c1851c
Update python/cudf/cudf/core/udf/row_function.py
brandon-b-miller Sep 14, 2022
5ca6abc
Remove extraneous include.
vyasr Sep 14, 2022
356135b
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
vyasr Sep 14, 2022
c0ce94a
Move to_string_view_array into the appropriate namespaces.
vyasr Sep 14, 2022
0867205
Add missing nogil and except +.
vyasr Sep 14, 2022
c4f9133
Use auto.
vyasr Sep 14, 2022
23b3020
Add consts.
vyasr Sep 14, 2022
51ac693
Commit missed detail header with detail::to_string_view_array declara…
vyasr Sep 14, 2022
84b4d4b
Add missing stream parameter.
vyasr Sep 14, 2022
f2e52cf
fix bugs with imported implementation names
brandon-b-miller Sep 14, 2022
2f47e9f
Remove header exposing detail API.
vyasr Sep 14, 2022
b1a5fa6
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
brandon-b-miller Sep 14, 2022
ab87921
Fix style.
vyasr Sep 14, 2022
07dbded
address other reviews
brandon-b-miller Sep 14, 2022
c3b0221
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
brandon-b-miller Sep 14, 2022
c1f686d
refactor _typing and strings_typing
brandon-b-miller Sep 14, 2022
7975606
style
brandon-b-miller Sep 14, 2022
6080e25
import funcs from strings_udf
brandon-b-miller Sep 14, 2022
b2062ea
fix len test
brandon-b-miller Sep 14, 2022
f964da4
add more doxygen to count()
davidwendt Sep 14, 2022
2e19a66
Remove unneeded header includes
davidwendt Sep 14, 2022
b7ad6c9
Update python/strings_udf/strings_udf/tests/test_string_udfs.py
brandon-b-miller Sep 14, 2022
345e417
Update python/cudf/cudf/tests/test_udf_masked_ops.py
brandon-b-miller Sep 14, 2022
b8fe76f
docs
brandon-b-miller Sep 14, 2022
c2b1267
elaborate on table_ptr
brandon-b-miller Sep 14, 2022
1f8cb3b
use in ci/cpu/build.sh
brandon-b-miller Sep 14, 2022
78e1078
add strings_udf to upload.sh
brandon-b-miller Sep 14, 2022
24090de
merge 22.10
brandon-b-miller Sep 19, 2022
db0c589
revert to building package for different python versions manually
brandon-b-miller Sep 19, 2022
b88def9
merge 22.10 again
brandon-b-miller Sep 19, 2022
cf0ae5b
Explicitly catch return code instead of relying on a function.
vyasr Sep 19, 2022
15aacc2
merge latest from 22.10
brandon-b-miller Sep 20, 2022
cda1415
Merge branch 'string_udfs' of github.com:brandon-b-miller/cudf into s…
brandon-b-miller Sep 20, 2022
40e6cd6
style
brandon-b-miller Sep 20, 2022
036eeec
cudf/core/udf/__init__.py is sensitive to import order, skip on isort
brandon-b-miller Sep 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
from cudf.core.index import Index, RangeIndex, _index_from_columns
from cudf.core.missing import NA
from cudf.core.multiindex import MultiIndex
from cudf.core.udf.utils import _compile_or_get, _supported_cols_from_frame
from cudf.core.udf.utils import (
_compile_or_get,
_launch_arg_from_col,
_post_process_output_col,
_return_col_from_dtype,
_supported_cols_from_frame,
)
from cudf.utils import docutils
from cudf.utils.utils import _cudf_nvtx_annotate

Expand Down Expand Up @@ -1797,20 +1803,15 @@ def _apply(self, func, kernel_getter, *args, **kwargs):
) from e

# Mask and data column preallocated
ans_col = cp.empty(len(self), dtype=retty)
ans_col = _return_col_from_dtype(retty, len(self))
ans_mask = cudf.core.column.column_empty(len(self), dtype="bool")
launch_args = [(ans_col, ans_mask), len(self)]
offsets = []

# if _compile_or_get succeeds, it is safe to create a kernel that only
# consumes the columns that are of supported dtype
for col in _supported_cols_from_frame(self).values():
data = col.data
mask = col.mask
if mask is None:
launch_args.append(data)
else:
launch_args.append((data, mask))
launch_args.append(_launch_arg_from_col(col))
offsets.append(col.offset)
launch_args += offsets
launch_args += list(args)
Expand All @@ -1820,7 +1821,8 @@ def _apply(self, func, kernel_getter, *args, **kwargs):
except Exception as e:
raise RuntimeError("UDF kernel execution failed.") from e

col = cudf.core.column.as_column(ans_col)
col = _post_process_output_col(ans_col, retty)

col.set_base_mask(libcudf.transform.bools_to_mask(ans_mask))
result = cudf.Series._from_data({None: col}, self._index)

Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/core/udf/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import typing, lowering
# Copyright (c) 2022, NVIDIA CORPORATION.
from . import masked_typing, masked_lowering, strings_typing, strings_lowering
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
)
from numba.extending import lower_builtin, types

from strings_udf._typing import string_view

from cudf.core.udf import api
from cudf.core.udf._ops import (
arith_ops,
bitwise_ops,
comparison_ops,
unary_ops,
)
from cudf.core.udf.typing import MaskedType, NAType
from cudf.core.udf.masked_typing import MaskedType, NAType


@cuda_lowering_registry.lower_constant(NAType)
Expand Down Expand Up @@ -62,7 +64,6 @@ def masked_scalar_op_impl(context, builder, sig, args):
result = cgutils.create_struct_proxy(masked_return_type)(
context, builder
)

# compute output validity
valid = builder.and_(m1.valid, m2.valid)
result.valid = valid
Expand Down Expand Up @@ -280,6 +281,7 @@ def pack_return_masked_impl(context, builder, sig, args):
@cuda_lower(api.pack_return, types.Number)
@cuda_lower(api.pack_return, types.NPDatetime)
@cuda_lower(api.pack_return, types.NPTimedelta)
@cuda_lower(api.pack_return, string_view)
def pack_return_scalar_impl(context, builder, sig, args):
outdata = cgutils.create_struct_proxy(sig.return_type)(context, builder)
outdata.value = args[0]
Expand Down Expand Up @@ -351,6 +353,7 @@ def cast_masked_to_masked(context, builder, fromty, toty, val):
@lower_builtin(api.Masked, types.Number, types.boolean)
@lower_builtin(api.Masked, types.NPDatetime, types.boolean)
@lower_builtin(api.Masked, types.NPTimedelta, types.boolean)
@lower_builtin(api.Masked, string_view, types.boolean)
def masked_constructor(context, builder, sig, args):
ty = sig.return_type
value, valid = args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from numba.core.typing.typeof import typeof
from numba.cuda.cudadecl import registry as cuda_decl_registry

from strings_udf._typing import StringView, string_view

from cudf.core.missing import NA
from cudf.core.udf import api
from cudf.core.udf._ops import (
Expand All @@ -32,9 +34,11 @@
types.Boolean,
types.NPDatetime,
types.NPTimedelta,
types.PyObject,
)


# Masked scalars of all types
class MaskedType(types.Type):
"""
A Numba type consisting of a value of some primitive type
Expand All @@ -44,7 +48,12 @@ class MaskedType(types.Type):
def __init__(self, value):
# MaskedType in Numba shall be parameterized
# with a value type
if isinstance(value, SUPPORTED_NUMBA_TYPES):

# TODO - replace object with stringview immediately
if isinstance(value, (types.PyObject, StringView)):
self.value_type = string_view

elif isinstance(value, SUPPORTED_NUMBA_TYPES):
self.value_type = value
else:
# Unsupported Dtype. Numba tends to print out the type info
Expand All @@ -54,9 +63,9 @@ def __init__(self, value):
self.value_type = types.Poison(
"\n\n\n Unsupported MaskedType. This is usually caused by "
"attempting to use a column of unsupported dtype in a UDF. "
f"Supported dtypes are {SUPPORTED_NUMBA_TYPES}"
f"Supported dtypes are {SUPPORTED_NUMBA_TYPES}\n\n\n"
)
super().__init__(name=f"Masked{self.value_type}")
super().__init__(name=f"Masked({self.value_type})")

def __hash__(self):
"""
Expand Down Expand Up @@ -145,6 +154,7 @@ class MaskedConstructor(ConcreteTemplate):
| datetime_cases
| timedelta_cases
| {types.boolean}
| {string_view}
)
]

Expand Down
22 changes: 17 additions & 5 deletions python/cudf/cudf/core/udf/row_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
from numba.np import numpy_support
from numba.types import Record

from strings_udf._typing import DString

from cudf.core.udf.api import Masked, pack_return
from cudf.core.udf.masked_typing import MaskedType
from cudf.core.udf.templates import (
masked_input_initializer_template,
row_initializer_template,
row_kernel_template,
unmasked_input_initializer_template,
)
from cudf.core.udf.typing import MaskedType
from cudf.core.udf.utils import (
_all_dtypes_from_frame,
_construct_signature,
Expand All @@ -24,6 +26,8 @@
_supported_dtypes_from_frame,
)

dstring = DString()
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved


def _get_frame_row_type(dtype):
"""
Expand All @@ -45,7 +49,13 @@ def _get_frame_row_type(dtype):
fields = []
offset = 0

sizes = [val[0].itemsize for val in dtype.fields.values()]
sizes = []
for field in dtype.fields.values():
if field[0] == np.dtype("object"):
sizes.append(dstring.size_bytes)
else:
sizes.append(field[0].itemsize)

for i, (name, info) in enumerate(dtype.fields.items()):
# *info* consists of the element dtype, its offset from the beginning
# of the record, and an optional "title" containing metadata.
Expand All @@ -62,7 +72,11 @@ def _get_frame_row_type(dtype):
fields.append((name, infos))

# increment offset by itemsize plus one byte for validity
offset += elemdtype.itemsize + 1
if elemdtype == np.dtype("object"):
itemsize = dstring.size_bytes
else:
itemsize = elemdtype.itemsize
offset += itemsize + 1

# Align the next member of the struct to be a multiple of the
# memory access size, per PTX ISA 7.4/5.4.5
Expand Down Expand Up @@ -127,10 +141,8 @@ def _get_row_kernel(frame, func, args):
np.dtype(list(_all_dtypes_from_frame(frame).items()))
)
scalar_return_type = _get_udf_return_type(row_type, func, args)

# this is the signature for the final full kernel compilation
sig = _construct_signature(frame, scalar_return_type, args)

# this row type is used within the kernel to pack up the column and
# mask data into the dict like data structure the user udf expects
np_field_types = np.dtype(
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/udf/scalar_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from numba.np import numpy_support

from cudf.core.udf.api import Masked, pack_return
from cudf.core.udf.masked_typing import MaskedType
from cudf.core.udf.templates import (
masked_input_initializer_template,
scalar_kernel_template,
unmasked_input_initializer_template,
)
from cudf.core.udf.typing import MaskedType
from cudf.core.udf.utils import (
_construct_signature,
_get_kernel,
Expand Down
Loading