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

`frompyfunc` requires `dtype=object` when used with `accumulate` #4155

Open
hpaulj opened this Issue Dec 29, 2013 · 1 comment

Comments

Projects
None yet
2 participants
@hpaulj
Contributor

hpaulj commented Dec 29, 2013

np.frompyfunc(lambda x,y:x+y,2,1).accumulate(np.arange(10))

raises an error:

ValueError: could not find a matching type for <lambda> (vectorized).accumulate, requested type has type code 'l'

accumulate only works if the dtype is set explicitly to object (either in the input, the out array, or as a kwarg).

np.frompyfunc(lambda x,y:x+y,2,1).accumulate(np.arange(10,dtype=object))

This behavior may be consistent with the note in its doc that The returned ufunc always returns PyObject arrays.. Also when vectorize uses a ufunc generated by this function, it converts the args to object type, and then converts the output to a specified (or deduced) otype.

However, is this error message required? A straight call of the ufunc returns an object array without any warning or error message:

np.frompyfunc(lambda x:2*x,1,1)(np.arange(4))
# array([0, 2, 4, 6], dtype=object)

Or is this just documentation issue? Does its __doc__ need an added note?

@jakirkham

This comment has been minimized.

Contributor

jakirkham commented Dec 8, 2017

Probably does some casting under the hood (speculating as I have not looked). Maybe that is an option for accumulate too?

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