Add ability to use bools in UDF type annotations#111
Merged
Conversation
This commit adds extensive test coverage for np.bool_ and bool types in Python UDFs, including both scalar (non-vector) and vector operations. Changes: - Added np.bool_ to numpy_type_map in signature.py for proper type signature resolution - Added bool UDF implementations in ext_funcs/__init__.py: * Scalar operations: bool_and, bool_or, bool_not, bool_xor * Vector operations for numpy, pandas, polars, and pyarrow * Nullable variants for all frameworks * Masked variants with explicit null handling - Added test data in test.sql: * bool_data table with non-nullable bool columns * bool_data_with_nulls table for testing null handling - Added integration tests in test_ext_func.py: * 4 scalar bool tests (and, or, not, xor) * 4 vector non-nullable tests (numpy, pandas, polars, arrow) * 5 nullable tests (scalar + 4 frameworks) * 4 masked tests (all frameworks) - Added type signature tests in test_udf.py: * bool and np.bool_ type mapping * Optional[bool] nullable mapping * List[bool] vector mapping * Bool return types Special handling for pyarrow: - Converts TINYINT (0/1) to bool using pc.not_equal(x, 0) - Converts bool results back to int8 for proper serialization All tests passing, pre-commit hooks clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds support for using boolean types in User-Defined Function (UDF) type annotations for SingleStoreDB, enabling developers to use bool and np.bool_ types in their UDF signatures. The implementation correctly handles the Python type system where bool is a subclass of int, ensuring proper type resolution and SQL mapping.
Key changes:
- Extended type mapping system to recognize bool types (both Python's built-in
booland NumPy'snp.bool_) - Added comprehensive test coverage for scalar, vector, nullable, and masked bool operations across multiple data processing libraries
- Created test data fixtures for bool validation with and without nulls
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| singlestoredb/functions/signature.py | Added bool type mappings to numpy_type_map and int_type_map for proper type normalization |
| singlestoredb/tests/test_udf.py | Added unit tests verifying bool type annotations generate correct SQL signatures for parameters and return types |
| singlestoredb/tests/test_ext_func.py | Added comprehensive integration tests for bool UDFs including scalar operations (AND, OR, NOT, XOR), vector operations, and nullable variants across numpy, pandas, polars, and pyarrow |
| singlestoredb/tests/test.sql | Created test tables bool_data and bool_data_with_nulls with appropriate bool column configurations |
| singlestoredb/tests/ext_funcs/init.py | Implemented bool UDF test functions following existing patterns, including explicit BOOL dtype decorators and library-specific implementations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.