Skip to content

BUG: Multiplying strings by int fails with ArrowNotImplementedError: #51970

Closed
@rohanjain101

Description

@rohanjain101

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

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

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arrowpyarrow functionalityBugNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions