Skip to content

BUG: np.asscalar should pass through scalars #10256

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

seawolf631
Copy link

@seawolf631 seawolf631 commented Dec 22, 2017

Closes #4701

return a.item()
try:
return a.item()
except AttributeError, e:
Copy link
Member

Choose a reason for hiding this comment

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

Deprecated syntax, just use except AttributeError

@eric-wieser
Copy link
Member

Right now this just duplicates #5126 - so make sure to address the comments there

@charris charris changed the title Attempt to fix issue #4701, np.asscalar should pass through scalars BUG: np.asscalar should pass through scalars Dec 23, 2017
@seawolf631
Copy link
Author

My new changes pass through all scalars, and then for arrays of size greater than 1 you get a ValueError of "Array needs to be of size 1".

@eric-wieser
Copy link
Member

eric-wieser commented Dec 27, 2017

This changed the behavior of the following:

>>> type(np.asscalar(np.float64(1)))
numpy.float64  # previously float
>>> type(np.asscalar(np.array(1.0)))
float  # as before

This function strikes me as one in the "mistake we're now stuck with" category, which might be best to just leave alone. Calling item() in general is a pretty bad idea.

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.

3 participants