You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: inconsistency between str.center and np.char.center #25659
The original string is returned if width is less than or equal to len(s).
And the docs for np.char.center say:
Calls :meth:`str.center` element-wise.
but observe:
In [1]: np.char.center(["this is a string that's longer than the width", "a"], 10)
Out[1]: array(['this is a ', ' a '], dtype='<U10')
In [2]: "this is a string that's longer than the width".center(10)
Out[2]: "this is a string that's longer than the width"
Now I can see why the _vec_string implementations (and probably future ufunc implementations from @lysnikolaou) are written this way. I'm perfectly happy to keep this difference compared with str.center, but we should intentionally choose that and document it in the affected functions. I'm happy to implement whichever behavior we decide on in stringdtype.
No strong opinion. The fix would also be trivial and just bloat memory a bit if it isn't a bug fix. Since the problem is probably just the returned string space needed is max(center, old_size) rather than just center.
Activity
seberg commentedon Jan 25, 2024
No strong opinion. The fix would also be trivial and just bloat memory a bit if it isn't a bug fix. Since the problem is probably just the returned string space needed is
max(center, old_size)rather than justcenter.