Skip to content

ENH: __array_function__ for np.core.defchararray #12154

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 2 commits into from
Oct 19, 2018

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Oct 12, 2018

xref #12028

return (a,)


@array_function_dispatch(_partition_dispatcher)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it makes sense to use lambda in these simple cases

Copy link
Member Author

@shoyer shoyer Oct 12, 2018

Choose a reason for hiding this comment

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

Yeah... I think there's a strong case for saying that it if fits on a single line with lambda, use that instead of a separate dispatcher (see my latest commit).

The downside is that it can look a little dense when there are a few arguments, e.g.,

@array_function_dispatch(lambda a, old, new, count=None: (a,))
def replace(a, old, new, count=None):
    ...

Copy link
Member Author

Choose a reason for hiding this comment

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

@mhvk @hameerabbasi any opinions on the style here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, let's move discussion to the master issue.

Copy link
Member

Choose a reason for hiding this comment

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

Could line wrap weirdly as:

@array_function_dispatch(lambda
            a, old, new, count=None: (a,))
def replace(a, old, new, count=None):
    ...

Copy link
Member Author

Choose a reason for hiding this comment

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

I do like this wrapped version (added to the example in the master issue):

@array_function_dispatch(
    lambda a, old, new, count=None: (a,)
)
def replace(a, old, new, count=None):
    ...

@eric-wieser
Copy link
Member

What is CLN as a prefix?

@shoyer
Copy link
Member Author

shoyer commented Oct 12, 2018

I've been using "CLN" for "cleanup"... but maybe that's not in our official list? :)

@@ -377,6 +399,11 @@ def capitalize(a):
return _vec_string(a_arr, a_arr.dtype, 'capitalize')


def _center_dispatcher(a, width, fillchar=None):
return (a,)
Copy link
Member

Choose a reason for hiding this comment

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

This is now unused

Copy link
Member

Choose a reason for hiding this comment

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

It appears in the call in line 422. Do you mean not tested?

Copy link
Member Author

Choose a reason for hiding this comment

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

I reverted my later commit that made this unused. So now it definitely is used.

@eric-wieser
Copy link
Member

eric-wieser commented Oct 12, 2018

I don't actually feel strongly about the lambdas thing, but it would be nice to be consistent with some of the already merged PRs. If you think it's better as lambdas, then perhaps we should revisit the existing non-lambda usage. Perhaps that should be discussed on the tracking issue?

@tylerjereddy
Copy link
Contributor

Azure missing from the CI list -- not sure why -- I'll open an issue

@eric-wieser
Copy link
Member

Yep, CLN doesn't appear on our list - I think MAINT would be closest.

@shoyer
Copy link
Member Author

shoyer commented Oct 13, 2018

I decided to revert the commits switching to use lambda for the sake of consistency for now -- we can change these later if desired per discussion in the tracking issue.

Copy link
Contributor

@hameerabbasi hameerabbasi left a comment

Choose a reason for hiding this comment

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

This is all green from my end.

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Looks all OK to me too.

@mhvk mhvk merged commit f0ce97e into numpy:master Oct 19, 2018
@charris charris changed the title ENH: __array_function__ for np.core.defchararray ENH: __array_function__ for np.core.defchararray Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants