numpy/char-module
| Rule | char-module |
|---|---|
| Pack | NumPy |
| Severity | info |
| Fix | unsafe, with xpd check --fix --unsafe-fixes |
| Library versions | NumPy 2.0 and later |
numpy.char is legacy, and NumPy's docs point to numpy.strings. Call the function of the same name in np.strings.
names = np.char.upper(names)names = np.strings.upper(names)What the rule reports
Section titled “What the rule reports”The rule reports a function of np.char when np.strings, added in NumPy 2.0, has a function of the same name. NumPy's docs call np.char legacy.
How to fix it
Section titled “How to fix it”xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.
The safe fix writes np.strings.upper and every other name that is the same function in both modules. Unsafe: the comparisons, such as np.strings.equal, which do not strip trailing whitespace, and np.strings.multiply, which raises a different error on bad input. Unsafe also: partition and rpartition, because np.strings returns a tuple of three arrays.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
numpy.char is legacy, and NumPy's docs say to use numpy.strings. Write $NP.strings.$F.Browse the other rules of the NumPy pack.