8000 Let apply_along_axis work with more function return types: Issue/2582 by oracal · Pull Request #5323 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Let apply_along_axis work with more function return types: Issue/2582 #5323

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

Closed
wants to merge 2 commits into from

Conversation

oracal
Copy link
@oracal oracal commented Nov 29, 2014

Fixed issue #2582. If the function passed into the apply_along_axis function returned anything other than a "scalar" or "array-like object" then it would throw an exception that len method did not exist.


def test_function_returning_non_scalar(self):
def return_none(x):
pass
Copy link
Member

Choose a reason for hiding this comment

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

Be best to have a blank line after the function definition, and also class definition in the next test.

@charris
Copy link
Member
charris commented Nov 30, 2014

The commit messages should be expanded a bit. First, the summaries should begin with BUG: , then follow with an explanation of what the problem was and what the fix is. You can use git rebase -i HEAD^^ to make the changes and a force push to origin to update this PR.

@charris charris changed the title Issue/2582 Let apply_along_axis work with more function return types: Issue/2582 Jan 11, 2015
@@ -90,7 +90,13 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
i.put(indlist, ind)
res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
# if res is a number, then we have a smaller output array
if isscalar(res):
asscalar = isscalar(res)
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be simpler to just do

if isscalar or not hasattr(res, `__len__`):

Even so, for better behavior I'd probably save the results of applying func in a list, make a array out of that, and then reshape it. One could instead maybe do asarray(res) up front .and check the dimension of that. I think that would solve the problem here and also work for functions that, say, return a set constructed from the elements of the axis and that currently fail.

@homu
Copy link
Contributor
homu commented Oct 11, 2016

☔ The latest upstream changes (presumably 84b11f5) made this pull request unmergeable. Please resolve the merge conflicts.

@eric-wieser
Copy link
Member
eric-wieser commented Feb 13, 2017

@oracal: I think these tests all pass as of #8441 (by using asarray).

@oracal oracal closed this Feb 13, 2017
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.

7 participants
0