Skip to content
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

FIX-#6287: Fix handling of numpy array_function #6288

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

RehanSD
Copy link
Collaborator

@RehanSD RehanSD commented Jun 23, 2023

What do these changes do?

  • first commit message and PR title follow format outlined here

    NOTE: If you edit the PR title to match this format, you need to add another commit (even if it's empty) or amend your last commit for the CI job that checks the PR title to pick up the new PR title.

  • passes flake8 modin/ asv_bench/benchmarks scripts/doc_checker.py
  • passes black --check modin/ asv_bench/benchmarks scripts/doc_checker.py
  • signed commit with git commit -s
  • Resolves #?
  • tests added and passing
  • module layout described at docs/development/architecture.rst is up-to-date

@RehanSD RehanSD requested a review from a team as a code owner June 23, 2023 20:29
RehanSD added 3 commits June 23, 2023 13:31
Signed-off-by: Rehan Durrani <[email protected]>
Signed-off-by: Rehan Durrani <[email protected]>
Signed-off-by: Rehan Durrani <[email protected]>
@anmyachev
Copy link
Collaborator

@RehanSD CI is broken

@@ -3426,6 +3426,80 @@ def __and__(self, other):
def __rand__(self, other):
return self._binary_op("__rand__", other, axis=0)

def __array_function__(self, func, types, args, kwargs):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both array_ufunc and array_function will not work if the user passes in a Modin NumPy Array for out if we end up defaulting to NumPy. In the Modin NumPy API, I've fixed it so that we do copy in the values to a Modin NumPy Array, but I'm not sure what the solution should be for this, and so have defaulted to having it be unsupported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where this "unsupported" is placed in code. I think it should be an exception or something similar, shouldn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump

RehanSD added 2 commits June 27, 2023 16:51
Signed-off-by: Rehan Durrani <[email protected]>
Signed-off-by: Rehan Durrani <[email protected]>
# If `out` is a modin.numpy.array, `kwargs.get("out")` returns a 1-tuple
# whose only element is that array, so we need to unwrap it from the tuple.
out_kwarg = out_kwarg[0]
kwargs.pop("out", None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should merge the .get and .pop like

out_kwarg = kwargs.pop("out", None)

I see no point of keeping them separated

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

modin/numpy/arr.py Outdated Show resolved Hide resolved
if where_kwarg is not None:
if hasattr(where_kwarg, "_query_compiler"):
kwargs["where"] = where_kwarg.__array__()
return func(arr, *converted_args[1:], **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be losing converteg_args[0] (which was args[0]), feels weird

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add a comment - but basically args[0] is self. Since we’re calling the function directly instead of calling the special method again, I’m passing in the converted self as the first argument, and only need to pass in any remaining args (after making sure to convert them)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a comment would be nice; also, if we're dropping converted_args[0], then we should probably be doing so in the upper loop and skip the call of args[0].__array__() altogether

Co-authored-by: Vasily Litvinov <[email protected]>
@@ -397,10 +397,29 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
if isinstance(input, pd.Series):
input = input._query_compiler.to_numpy().flatten()
args += [input]
out_kwarg = kwargs.get("out", None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out_kwarg = kwargs.get("out", None)
out_kwarg = kwargs.pop("out", None)

# If `out` is a modin.numpy.array, `kwargs.get("out")` returns a 1-tuple
# whose only element is that array, so we need to unwrap it from the tuple.
out_kwarg = out_kwarg[0]
kwargs.pop("out", None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
kwargs.pop("out", None)

@@ -3426,6 +3426,80 @@ def __and__(self, other):
def __rand__(self, other):
return self._binary_op("__rand__", other, axis=0)

def __array_function__(self, func, types, args, kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump

if where_kwarg is not None:
if hasattr(where_kwarg, "_query_compiler"):
kwargs["where"] = where_kwarg.__array__()
return func(arr, *converted_args[1:], **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a comment would be nice; also, if we're dropping converted_args[0], then we should probably be doing so in the upper loop and skip the call of args[0].__array__() altogether

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants