-
Notifications
You must be signed in to change notification settings - Fork 655
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
FEAT-#6301: Simplify usage of algebra operators to define custom functions #6302
base: master
Are you sure you want to change the base?
Changes from all commits
990ec17
ac9732e
5899084
e9f5dcd
ee354fd
884224e
96089da
d65387e
3f3cc5b
52eeecc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,7 +297,7 @@ def register( | |
""" | ||
|
||
def caller( | ||
query_compiler, other, broadcast=False, *args, dtypes=None, **kwargs | ||
query_compiler, other, *args, broadcast=False, dtypes=None, **kwargs | ||
): | ||
""" | ||
Apply binary `func` to passed operands. | ||
|
@@ -414,3 +414,43 @@ def caller( | |
) | ||
|
||
return caller | ||
|
||
@classmethod | ||
def apply( | ||
cls, left, right, func, axis=0, func_args=None, func_kwargs=None, **kwargs | ||
): | ||
r""" | ||
Apply a binary function row-wise or column-wise. | ||
|
||
Parameters | ||
---------- | ||
left : modin.pandas.DataFrame or modin.pandas.Series | ||
Left operand. | ||
right : modin.pandas.DataFrame or modin.pandas.Series | ||
Right operand. | ||
Comment on lines
+427
to
+430
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This layer depends on the upper layer in every apply. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The lower layer still takes the object(s) from the API layer, namely, modin.pandas.DataFrame/Series. Then, there is a |
||
func : callable(pandas.DataFrame, pandas.DataFrame, \*args, axis, \*\*kwargs) -> pandas.DataFrame | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the signature is wrong here, as the implementation explicitly passes Query Compilers as arguments... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, follow the track of the
|
||
A binary function to apply `left` and `right`. | ||
axis : int, default: 0 | ||
Whether to apply the function across rows (``axis=0``) or across columns (``axis=1``). | ||
func_args : tuple, optional | ||
Positional arguments to pass to the funcs. | ||
func_kwargs : dict, optional | ||
Keyword arguments to pass to the funcs. | ||
**kwargs : dict | ||
Additional arguments to pass to the ``cls.register()``. | ||
|
||
Returns | ||
------- | ||
The same type as `df`. | ||
""" | ||
operator = cls.register(func, **kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder what is the purpose of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, that's the only way of how we can get the |
||
|
||
qc_result = operator( | ||
left._query_compiler, | ||
right._query_compiler, | ||
broadcast=right.ndim == 1, | ||
*(func_args or ()), | ||
axis=axis, | ||
**(func_kwargs or {}), | ||
) | ||
return left.__constructor__(query_compiler=qc_result) |
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.
changed the order so the function's positional arguments won't conflict with the keyword
broadcast
arg.