Skip to content

DeprecatedWarning: apply_along_axis and dtype=object #17249

@f380cedric

Description

@f380cedric

Since #15119, np.apply_along_axis throws a DeprecatedWarning when func1d returns object dtype.
I am using it with scipy.signal.find_peaks since it easily allows to keep shape, Numpy's indexing style, etc.
I am expecting that it will become an error at some point in the future.

Would it be possible to add a dtype kwarg?

Reproducing code example:

import numpy as np
def foo(dummy):
    return 1,"1",[1],(1,)

arr = np.apply_along_axis(foo, -1, np.random.randn(5,2,200))

Error message:

/usr/lib/python3/dist-packages/numpy/core/_asarray.py:136: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

Numpy/Python version information:

1.19.1 3.8.5 (default, Aug  2 2020, 15:09:07)
[GCC 10.2.0]

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