-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-50968][PYTHON] Fix the usage of
Column.__new__
### What changes were proposed in this pull request? Fixes the usage of `Column.__new__`. ### Why are the changes needed? Currently `Column.__init__` is called in `Column.__new__`, but it will call `__init__` twice, because it will be automatically called from Python, so it doesn't need to be explicitly called in `__new__`. ```py >>> class A: ... def __new__(cls, *args, **kwargs): ... print(f"__NEW__: {args}, {kwargs}") ... obj = object.__new__(cls) ... obj.__init__(*args, **kwargs) ... return obj ... def __init__(self, *args, **kwargs): ... print(f"__INIT__: {args}, {kwargs}") ... >>> A(1,2,3, k=4) __NEW__: (1, 2, 3), {'k': 4} __INIT__: (1, 2, 3), {'k': 4} __INIT__: (1, 2, 3), {'k': 4} <__main__.A object at 0x102ccab90> >>> class B: ... def __new__(cls, *args, **kwargs): ... print(f"__NEW__: {args}, {kwargs}") ... return object.__new__(cls) ... def __init__(self, *args, **kwargs): ... print(f"__INIT__: {args}, {kwargs}") ... >>> B(1,2,3, k=4) __NEW__: (1, 2, 3), {'k': 4} __INIT__: (1, 2, 3), {'k': 4} <__main__.B object at 0x102b2b970> ``` ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? The existing tests should pass. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #49631 from ueshin/issues/SPARK-50968/column_new. Authored-by: Takuya Ueshin <[email protected]> Signed-off-by: Takuya Ueshin <[email protected]>
- Loading branch information
Showing
5 changed files
with
39 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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