jbrockmendel commented on issue #15053: URL: https://github.com/apache/arrow/issues/15053#issuecomment-2315732406
I think this might still not match the cpython behavior. Based on the OP and https://github.com/pandas-dev/pandas/pull/59624 (the pandas test test_center_ljust_rjust_fillchar) ``` In [19]: a1 = "a" In [20]: a1.center(5, "X") Out[20]: 'XXaXX' In [21]: pc.utf8_center(pa.scalar(a1), 5, padding="X", lean_left_on_odd_padding=True) Out[21]: <pyarrow.StringScalar: 'XXaXX'> ``` So far so good. But when the input string has an even number of characters: ``` In [22]: b4 = "bbbb" In [23]: b4.center(5, "X") Out[23]: 'Xbbbb' In [24]: pc.utf8_center(pa.scalar(b4), 5, padding="X", lean_left_on_odd_padding=True) Out[24]: <pyarrow.StringScalar: 'bbbbX'> ``` IIUC with lean_left_on_odd_padding=True the number of spaces to put on right/left is determined [here](https://github.com/apache/arrow/blob/6b268f62a8a172249ef35f093009c740c32e1f36/cpp/src/arrow/compute/kernels/scalar_string_utf8.cc#L934) as ``` left = spaces / 2; right = spaces - left; ``` By contrast in cpython it is determined [here](https://github.com/python/cpython/blob/40fff90ae3d46843bb9d27c6a53ef61c861a3bb4/Objects/stringlib/transmogrify.h#L203) as ``` marg = width - STRINGLIB_LEN(self) left = marg / 2 + (marg & width & 1); ``` With another dose of "IIUC", it looks like the `marg &width & 1` term is missing from the pyarrow version. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
