Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: No longer auto-convert array scalars to numpy scalars in ufuncs (and elsewhere?) #24897

Open
@mhvk

Description

@mhvk

Proposed new feature or change:

This may come too late, but numpy 2.0 may be a good opportunity to remove an irritating wart, that ufunc(array_scalar_arguments) returns a numpy scalar rather than an array scalar. There is a very long-standing PR (#14489) that introduces an option to avoid this (using out=...), but perhaps it is time to just ditch the conversion to scalar?

See gh-13105 for discussion. As a specific example of why it is unhandy, it mentions:

#13100 raises a case where np.fix resorts to calling np.asanyarray(np.ceil(x, out=out)) in order to ensure that the result is an array. Unfortunately, this has a number of draw-backs:

  • It discards duck-types, like dask arrays
  • It changes the dtype of 0d object arrays containing array-likes

The first comment on the issue by @rgommers suggests just removing the cast to scalar. To me, this still makes the most sense.

EDIT: the simplest implementation of this is to not use PyArray_Return in ufuncs, or perhaps adjust PyArray_Return to remove the try of converting to scalars altogether.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Descoped

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions