Skip to content

BUG: np.char.mod is broken #25332

Closed

Description

@ngoldbaum

Describe the issue:

It looks like np.char.mod is untested, so we missed it in the review of #25152.

Reproduce the code example:

import numpy as np
np.char.mod("%s", np.array(["hello", "world"]))

Error message:

File ~/.pyenv/versions/3.11.6/lib/python3.11/site-packages/numpy/_core/defchararray.py:412, in mod(a, values)
    391 @array_function_dispatch(_mod_dispatcher)
    392 def mod(a, values):
    393     """
    394     Return (a % i), that is pre-Python 2.6 string formatting
    395     (interpolation), element-wise for a pair of array_likes of str
   (...)
    410
    411     """
--> 412     return _to_bytes_or_str_array(
    413         _vec_string(a, object_, '__mod__', (values,)), a)

File ~/.pyenv/versions/3.11.6/lib/python3.11/site-packages/numpy/_core/defchararray.py:70, in _to_bytes_or_str_array(result, output_dtype_like)
     68     return result.astype(output_dtype_like.dtype)
     69 ret = numpy.asarray(result.tolist())
---> 70 return ret.astype(type(output_dtype_like.dtype)(_get_num_chars(ret)))

AttributeError: 'str' object has no attribute 'dtype'

Python and NumPy Versions:

2.0.0.dev0+git20231206.6ef3089
3.11.6 (main, Nov 27 2023, 12:13:52) [Clang 15.0.0 (clang-1500.0.40.1)]

Runtime Environment:

No response

Context for the issue:

ping @lysnikolaou

Activity

  1. lysnikolaou commented on Dec 7, 2023

    @lysnikolaou
    Member

    Actually, all np.char methods that have not been converted to ufuncs and return strings have this problem. Opened #25335 to fix it.

  2. changed the title [-]BUG: `np.char.mod` is broken[/-] [+]BUG: ``np.char.mod`` is broken[/+] on Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions