Commit 2f52688
authored
Add decorator for udwf (apache#1061)
* feat: Introduce create_udwf method for User-Defined Window Functions
- 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.
* refactor: Simplify UDWF test suite and introduce SimpleWindowCount evaluator
- 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.
* fix: Update type alias import to use typing_extensions for compatibility
* Add udwf tests for multiple input types and decorator syntax
* replace old def udwf
* refactor: Simplify df fixture by passing ctx as an argument
* refactor: Rename DataFrame fixtures and update test functions
- 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.
* refactor: Update udwf calls in WindowUDF to use BiasedNumbers directly
- 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).
* feat: Add overloads for udwf function to support multiple input types and decorator syntax
* refactor: Simplify udwf method signature by removing redundant type hints
* refactor: Remove state_type from udwf method signature and update return 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.
* refactor: Update volatility parameter type in udwf method signature to support Volatility enum
* Fix ruff errors
* fix C901 for def udwf
* refactor: Update udwf method signature and simplify input handling
- 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.
* refactor: Rename input_type to input_types in udwf method signature for clarity
* refactor: Enhance typing in udf.py by introducing Protocol for WindowEvaluator and improving import organization
* Revert "refactor: Enhance typing in udf.py by introducing Protocol for WindowEvaluator and improving import organization"
This reverts commit 16dbe5f.1 parent 4f45703 commit 2f52688
2 files changed
+264
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
621 | 621 | | |
622 | 622 | | |
623 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
624 | 634 | | |
625 | 635 | | |
626 | 636 | | |
627 | 637 | | |
628 | 638 | | |
629 | 639 | | |
630 | 640 | | |
631 | | - | |
632 | | - | |
| 641 | + | |
633 | 642 | | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
639 | 646 | | |
640 | | - | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
641 | 655 | | |
| 656 | + | |
| 657 | + | |
642 | 658 | | |
643 | 659 | | |
644 | 660 | | |
645 | 661 | | |
646 | 662 | | |
647 | 663 | | |
648 | | - | |
| 664 | + | |
| 665 | + | |
649 | 666 | | |
650 | 667 | | |
651 | 668 | | |
| |||
655 | 672 | | |
656 | 673 | | |
657 | 674 | | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
658 | 684 | | |
659 | | - | |
660 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
661 | 688 | | |
662 | 689 | | |
663 | | - | |
664 | 690 | | |
665 | 691 | | |
666 | 692 | | |
667 | | - | |
668 | | - | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
669 | 710 | | |
670 | 711 | | |
671 | 712 | | |
672 | 713 | | |
673 | 714 | | |
674 | 715 | | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
685 | 720 | | |
686 | 721 | | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
687 | 762 | | |
688 | 763 | | |
689 | 764 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
165 | 175 | | |
166 | 176 | | |
167 | 177 | | |
168 | 178 | | |
169 | 179 | | |
170 | | - | |
171 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
172 | 183 | | |
| 184 | + | |
| 185 | + | |
173 | 186 | | |
174 | 187 | | |
175 | 188 | | |
| |||
182 | 195 | | |
183 | 196 | | |
184 | 197 | | |
185 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
186 | 209 | | |
187 | 210 | | |
188 | 211 | | |
| |||
192 | 215 | | |
193 | 216 | | |
194 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
195 | 315 | | |
196 | 316 | | |
197 | 317 | | |
| |||
299 | 419 | | |
300 | 420 | | |
301 | 421 | | |
302 | | - | |
303 | | - | |
| 422 | + | |
| 423 | + | |
304 | 424 | | |
305 | 425 | | |
306 | 426 | | |
307 | 427 | | |
308 | 428 | | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
0 commit comments