-
Notifications
You must be signed in to change notification settings - Fork 133
Add decorator for udwf #1061
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
Merged
Merged
Add decorator for udwf #1061
Conversation
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
- Added `create_udwf` static method to `WindowUDF` class, allowing users to create User-Defined Window Functions (UDWF) as both a function and a decorator. - Updated type hinting for `_R` using `TypeAlias` for better clarity. - Enhanced documentation with usage examples for both function and decorator styles, improving usability and understanding.
…aluator - Removed multiple exponential smoothing classes to streamline the code. - Introduced SimpleWindowCount class for basic row counting functionality. - Updated test cases to validate the new SimpleWindowCount evaluator. - Refactored fixture and test functions for clarity and consistency. - Enhanced error handling in UDWF creation tests.
- Renamed `df` fixture to `complex_window_df` for clarity. - Renamed `simple_df` fixture to `count_window_df` to better reflect its purpose. - Updated test functions to use the new fixture names, enhancing readability and maintainability.
- Changed udwf1 to use BiasedNumbers instead of bias_10. - Added udwf2 to call udwf with bias_10. - Introduced udwf3 to demonstrate a lambda function returning BiasedNumbers(20).
… and decorator syntax
…urn type handling - Eliminated the state_type parameter from the udwf method to simplify the function signature. - Updated return type handling in the _function and _decorator methods to use a generic type _R for better type flexibility. - Enhanced the decorator to wrap the original function, allowing for improved argument handling and expression return.
…o support Volatility enum
- Changed the type hint for the return type in the _create_window_udf_decorator method to use pa.DataType directly instead of a TypeVar. - Simplified the handling of input types by removing redundant checks and directly using the input types list. - Removed unnecessary comments and cleaned up the code for better readability. - Updated the test for udwf to use parameterized tests for better coverage and maintainability.
…Evaluator and improving import organization
…r WindowEvaluator and improving import organization" This reverts commit 16dbe5f.
timsaucer
approved these changes
Mar 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for another excellent contribution!
|
@timsaucer |
4 tasks
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.
Which issue does this PR close?
Closes #1057.
Rationale for this change
This PR improves the WindowUDF.udwf function by making it more flexible and user-friendly. It introduces function overloads and allows usage as both a function and a decorator, improving usability and code clarity. Additionally, it expands test coverage to ensure correctness and robustness.
What changes are included in this PR?
Added function overloads to WindowUDF.udwf to support both function and decorator usage.
Refactored udwf to separate core logic into _create_window_udf and _create_window_udf_decorator for better maintainability.
Introduced helper methods _get_default_name and _normalize_input_types to simplify input handling.
Updated the test_udwf.py test suite to:
Add new test cases for function and decorator usage.
Introduce additional fixture-based DataFrame test setups.
Cover error cases, argument variations, and SQL registration scenarios.
Are there any user-facing changes?
Yes:
Users can now define WindowUDF functions using either a traditional function call or as a decorator.
Improved error handling and better default behavior when inferring names.
New test cases ensure correctness across different usage scenarios.
These changes are backward-compatible and enhance the developer experience when defining user-defined window functions.