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

Skip to content

BUG: index string ufunc promoter issues #27493

Closed
@ngoldbaum

Description

@ngoldbaum

At runtime, when the first argument is of dtype[str_] and StringDType dtype, the second argument can (also) be a native str, a (nested) sequence of str, or any other np.str_ array-like (including NDArray[str_]).

>>> np.char.index(np.array(["where's Wally?"], dtype=np.str_), "Wally")
array([8])
>>> np.char.index(np.array(["where's Wally?"], dtype=np.dtypes.StringDType()), "Wally")
array([8])
>>> np.char.index(np.array(["where's Wally?"], dtype=np.dtypes.StringDType()), np.str_("Wally"))
array([8])

But this doesn't appear to be the case when the dtypes "flipped", i.e.

>>> np.char.index(np.array(["where's Wally?"], dtype=np.str_), np.array("Wally", dtype=np.dtypes.StringDType()))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/.pyenv/versions/3.12.6/lib/python3.12/site-packages/numpy/_core/strings.py", line 327, in index
    return _index_ufunc(a, sub, start, end)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy._core._exceptions._UFuncNoLoopError: ufunc 'index' did not contain a loop with signature matching types (<class 'numpy.dtypes.StrDType'>, <class 'numpy.dtypes.StringDType'>, <class 'numpy.dtypes._PyLongDType'>, <class 'numpy.dtypes._PyLongDType'>) -> None

Originally posted by @jorenham in #27470 (comment)

Metadata

Metadata

Assignees

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