Only require numpy for the vectorized UDF path#538
Open
yvaishalirao wants to merge 1 commit into
Open
Conversation
…, but GetFunction() checked for numpy unconditionally before even branching on `vectorized`. Move the check inside that branch so native UDFs work without numpy installed.Fixes duckdb/duckdb#17052 (duckdb/duckdb#17052)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes duckdb/duckdb#17052 (duckdb/duckdb#17052)
create_function()was unnecessarily requiring numpy even for native UDFs that never use it.GetFunction()insrc/python_udf.cppimports/version-checks/warms-up numpy before determining if the vectorized mode was chosen. Only the vectorized path actually needs numpy, since it round-trips through pyarrow — the native path never touches either.Fix is one line, scoping that block inside
if (vectorized).Two new tests cover both directions:
test_scalar_native.py::test_native_udf_without_numpytest_scalar_arrow.py::test_arrow_udf_requires_numpyBoth run in a subprocess rather than monkeypatching
sys.modulesin-process — numpy's import cache (PythonImportCacheItem) lives for the whole interpreter process, so if numpy's already been imported by another test in the same worker, an in-process monkeypatch won't make the cache forget it. A fresh subprocess sidesteps that.Verified the test actually catches the regression by stashing the fix and running it both ways, numpy uninstalled in both:
'numpy' is required for this operation, but it wasn't installed