-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Closed
Closed
Copy link
Labels
Milestone
Description
Describe the issue:
I'm trying to migrate my project, named-arrays, to Numpy 2 and I'm having trouble overriding char.mod() / strings.mod() like I was able to do in Numpy 1. Is this intentional?
I thought at first that strings.mod must now be overridden by __array_ufunc__ instead of __array_function__, but I can't seem to get either of those methods to run.
Reproduce the code example:
values = DuckArray(4)
np.strings.mod("%.2f", values)Error message:
a = '%.2f', values = ScalarArray(ndarray=4, axes=())
@set_module("numpy.strings")
def mod(a, values):
"""
Return (a % i), that is pre-Python 2.6 string formatting
(interpolation), element-wise for a pair of array_likes of str
or unicode.
Parameters
----------
a : array_like, with `np.bytes_` or `np.str_` dtype
values : array_like of values
These values will be element-wise interpolated into the string.
Returns
-------
out : ndarray
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
depending on input types
Examples
--------
>>> import numpy as np
>>> a = np.array(["NumPy is a %s library"])
>>> np.strings.mod(a, values=["Python"])
array(['NumPy is a Python library'], dtype='<U25')
>>> a = np.array([b'%d bytes', b'%d bits'])
>>> values = np.array([8, 64])
>>> np.strings.mod(a, values)
array([b'8 bytes', b'64 bits'], dtype='|S7')
"""
return _to_bytes_or_str_array(
> _vec_string(a, np.object_, '__mod__', (values,)), a)
E TypeError: must be real number, not ScalarArray
..\..\AppData\Local\Programs\Python\Python313\Lib\site-packages\numpy\_core\strings.py:230: TypeErrorPython and NumPy Versions:
2.2.4
3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]