-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Description
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
import numpy as np
import pandas as pd
import pyarrow as pa
series = pd.Series([1.0, 2.0, 3.0], dtype=pd.ArrowDtype(pa.float64()))
series / np.array([2.0])
# ArrowInvalid: Array arguments must all be the same length
Issue Description
When performing arithmetic operations between a Series
of ArrowDtype
and a single-value array, the array is not broadcasted to match the series shape. Instead, it raises an ArrowInvalid error
. This behavior is inconsistent, as the same operation works correctly with both default and numpy-nullable dtypes.
A solution could be casting a single-element array to a pa.Scalar
in ArrowExtensionArray._evaluate_op_method
:
pandas/pandas/core/arrays/arrow/array.py
Line 755 in 2a10e04
def _evaluate_op_method(self, other, op, arrow_funcs) -> Self: |
Expected Behavior
The code doesn't fail, and behavior to be consistent over different dtype back-ends
Installed Versions
Pandas v2.2.3:
INSTALLED VERSIONS
------------------
commit : 0691c5cf90477d3503834d983f69350f250a6ff7
python : 3.12.7
python-bits : 64
OS : Darwin
OS-release : 24.0.0
Version : Darwin Kernel Version 24.0.0: Tue Sep 24 23:37:36 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.3
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
pip : 24.2
Cython : None
sphinx : 7.4.7
IPython : 8.26.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.6.1
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.4
lxml.etree : None
matplotlib : 3.8.4
numba : 0.60.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 16.1.0
pyreadstat : None
pytest : 8.3.2
python-calamine : None
pyxlsb : None
s3fs : 2024.6.1
scipy : 1.14.0
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
Nightly Pandas:
INSTALLED VERSIONS
------------------
commit : 2a10e04a099d5f1633abcdfbb2dd9fdf09142f8d
python : 3.12.7
python-bits : 64
OS : Darwin
OS-release : 24.0.0
Version : Darwin Kernel Version 24.0.0: Tue Sep 24 23:37:36 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 3.0.0.dev0+1579.g2a10e04a09
numpy : 2.2.0.dev0+git20241015.961b70f
dateutil : 2.9.0.post0
pip : 24.2
Cython : None
sphinx : None
IPython : 8.28.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : 17.0.0
pyreadstat : None
pytest : None
python-calamine : None
pytz : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.2
qtpy : None
pyqt5 : None