BUG: Multiplying strings by int fails with ArrowNotImplementedError: · Issue #51970 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

str1 = pd.Series(["abc", "abcd"], dtype="string[pyarrow]") str1 * 3

Traceback (most recent call last): File "", line 1, in File "C:\ca2_ps_env_3810\lib\site-packages\pandas\core\ops\common.py", line 72, in new_method return method(self, other) File "C:\ca2_ps_env_3810\lib\site-packages\pandas\core\arraylike.py", line 118, in mul return self._arith_method(other, operator.mul) File "C:\ca2_ps_env_3810\lib\site-packages\pandas\core\series.py", line 6259, in _arith_method return base.IndexOpsMixin._arith_method(self, other, op) File "C:\ca2_ps_env_3810\lib\site-packages\pandas\core\base.py", line 1325, in _arith_method result = ops.arithmetic_op(lvalues, rvalues, op) File "C:\ca2_ps_env_3810\lib\site-packages\pandas\core\ops\array_ops.py", line 218, in arithmetic_op res_values = op(left, right) File "C:\ca2_ps_env_3810\lib\site-packages\pandas\core\ops\common.py", line 72, in new_method return method(self, other) File "C:\ca2_ps_env_3810\lib\site-packages\pandas\core\arraylike.py", line 118, in mul return self._arith_method(other, operator.mul) File "C:\ca2_ps_env_3810\lib\site-packages\pandas\core\arrays\arrow\array.py", line 423, in _arith_method return self._evaluate_op_method(other, op, ARROW_ARITHMETIC_FUNCS) File "C:\ca2_ps_env_3810\lib\site-packages\pandas\core\arrays\arrow\array.py", line 412, in _evaluate_op_method result = pc_func(self._data, pa.scalar(other)) File "C:\ca2_ps_env_3810\lib\site-packages\pyarrow\compute.py", line 238, in wrapper return func.call(args, None, memory_pool) File "pyarrow_compute.pyx", line 355, in pyarrow._compute.Function.call File "pyarrow\error.pxi", line 144, in pyarrow.lib.pyarrow_internal_check_status File "pyarrow\error.pxi", line 121, in pyarrow.lib.check_status pyarrow.lib.ArrowNotImplementedError: Function 'multiply_checked' has no kernel matching input types (string, int64)

Issue Description

The operation of multiplying strings by int when the strings are stored using pd.StringDtype() is a repeat operation and succeeds, using pyarrow, it fails with ArrowNotImplementedError, does this mean that it's something that will be supported in the future? Is the expectation to have parity/consistency between the pandas backend and pyarrow backend?

Expected Behavior

I expect the behavior I get with pandas extension types:

>>> str2 = pd.Series(["abc", "abcd"], dtype=pd.StringDtype())
>>> str2
0     abc
1    abcd
dtype: string
>>> str2 * 3
0       abcabcabc
1    abcdabcdabcd
dtype: string

Installed Versions

pd.show_versions()
C:\ca2_ps_env_3810\lib\site-packages_distutils_hack_ init_.py:30: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS

commit : 91111fd
python : 3.8.10.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22621
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 7, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 1.5.1
numpy : 1.23.4
pytz : 2021.3
dateutil : 2.8.2
setuptools : 60.8.2
pip : 22.3.1
Cython : None
pytest : 7.0.1
hypothesis : None
sphinx : 4.2.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.1.1
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
brotli : None
fastparquet : 2023.2.0
fsspec : 2023.3.0
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 9.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None