[Numpy-discussion] String accessor methods

Todd toddrjen at gmail.com
Sun Mar 7 00:30:56 EST 2021


On Sat, Mar 6, 2021 at 12:57 PM dan_patterson <dan_patterson at outlook.com>
wrote:

> The are  in np.char
>
> mystr = np.array(["test first", "test second", "test third"])
>
> np.char.title(mystr)
> array(['Test First', 'Test Second', 'Test Third'], dtype='<U11')
>

I mentioned those in my email, but they are far less convenient to use than
class methods, nor do they relate well to how built-in strings are used in
Python. That is why other projects have started using accessor methods and
why Python removed all the separate string functions in Python 3.
The functions in np.char are also limited in their capabilities, and fairly
poorly documented in my opinion.  Some of those limitations are impossible
to overcome, for example they inherently can never support operators,
addition or multiplication, or slicing like Python strings can, while
an accessor could.

However, putting them as top-level methods for ndarray would pollute the
methods too much. That is why I am suggesting numpy do the same thing that
pandas, xarray, etc. are doing and putting those as methods under a 'str'
attribute for ndarrays rather than as separate functions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210307/ee506e6e/attachment.html>


More information about the NumPy-Discussion mailing list