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

Ufunc generates unintuitive AttributeError on object arrays (Trac #1013) #1611

Closed
thouis opened this issue Oct 19, 2012 · 12 comments
Closed

Comments

@thouis
Copy link
Contributor

thouis commented Oct 19, 2012

Original ticket http://projects.scipy.org/numpy/ticket/1013 on 2009-02-20 by @wesm, assigned to unknown.

This error is very unintuitive for end-users, arrays formed from SQL query results can frequently end up as object arrays by accident.

In [15]: arr = np.random.randn(100).astype(object)

In [16]: np.log(arr)

AttributeError Traceback (most recent call last)

H:\workspace\Python\src in ()

AttributeError: log

Same AttributeError is raised for other ufuncs

@thouis
Copy link
Contributor Author

thouis commented Oct 19, 2012

@rkern wrote on 2009-02-20

Can you suggest an error message text that you would have been more helpful?

@thouis
Copy link
Contributor Author

thouis commented Oct 19, 2012

Milestone changed to Unscheduled by @mwiebe on 2011-03-24

@thouis
Copy link
Contributor Author

thouis commented Oct 19, 2012

Title changed from Ufunc generates AttributeError on object arrays to Ufunc generates unintuitive AttributeError on object arrays by @mwiebe on 2011-03-24

@hayd
Copy link

hayd commented Jun 6, 2013

@hayd
Copy link

hayd commented Jun 6, 2013

Perhaps a better error message is:

TypeError("%s requires an array with numeric dtype but was passed %s" % ufunc, x.dtype)

(I think it should TypeError rather than an AttributeError...?)

When passing an array of strings to numpy.log you get:

TypeError: Not implemented for this type

I think this would also be improved with the above - more descriptive - message.

@njsmith
Copy link
Member

njsmith commented Jun 6, 2013

The reason for the AttributeError is that as a last ditch attempt, np.log
and friends on an object array will try doing obj.log(), and it's this last
ditch attempt that's failing.

I agree the message is tremendously confusing though and it's bitten me
several times. If you want to submit a pull request then many people would
be grateful.
On 6 Jun 2013 20:53, "Andy Hayden" notifications@github.com wrote:

Perhaps a better error message is:

TypeError("%s requires an array with numeric dtype but was passed %s" % ufunc, x.dtype)

(I think it should TypeError rather than an AttributeError...?)

When passing an array of strings to numpy.log you get:

TypeError: Not implemented for this type

I think this would also be improved with the above - more descriptive -
message.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1611#issuecomment-19069832
.

@hayd
Copy link

hayd commented Jun 6, 2013

Will have a look into it (probably sometime next week)...

@charris
Copy link
Member

charris commented Feb 20, 2014

@hayd Still pursuing this?

@ewmoore
Copy link
Contributor

ewmoore commented Feb 20, 2014

#368 seems related / duplicate.

@danielballan
Copy link
Contributor

Can anyone point me and/or @hayd to where in the code this can be fixed. I spent some time looking, but I don't understand the numpy internals well enough yet....

@juliantaylor
Copy link
Contributor

PyUFunc_O_O_method in ./numpy/core/src/umath/loops.c.src looks like the right spot

@eric-wieser
Copy link
Member

Closed in #12700

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

No branches or pull requests

9 participants