Skip to content

frompyfunc requires dtype=object when used with accumulate #4155

@hpaulj

Description

@hpaulj
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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions