-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Description
Reproducible Example
import pandas as pd
from pathlib import Path
pd.options.future.infer_string = True # Only needed with 2.3.1
folder = Path.cwd()
files = pd.Series(["a.png", "b.png"])
folder / files[0] # This works
folder / files # This raises an exception
Issue Description
The /
operator with Path
works fine with 2.3.1 with strings being object dtype, but not with arrow strings. The last statement produces this stacktrace:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\ops\common.py", line 76, in new_method
return method(self, other)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\arraylike.py", line 214, in __rtruediv__
return self._arith_method(other, roperator.rtruediv)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\series.py", line 6146, in _arith_method
return base.IndexOpsMixin._arith_method(self, other, op)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\base.py", line 1391, in _arith_method
result = ops.arithmetic_op(lvalues, rvalues, op)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\ops\array_ops.py", line 273, in arithmetic_op
res_values = op(left, right)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\roperator.py", line 27, in rtruediv
return right / left
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\ops\common.py", line 76, in new_method
return method(self, other)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\arraylike.py", line 214, in __rtruediv__
return self._arith_method(other, roperator.rtruediv)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\arrays\arrow\array.py", line 836, in _arith_method
return self._evaluate_op_method(other, op, ARROW_ARITHMETIC_FUNCS)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\arrays\arrow\array.py", line 768, in _evaluate_op_method
other = self._box_pa(other)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\arrays\arrow\array.py", line 407, in _box_pa
return cls._box_pa_scalar(value, pa_type)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\arrays\string_arrow.py", line 154, in _box_pa_scalar
pa_scalar = super()._box_pa_scalar(value, pa_type)
File "C:\Condadirs\envs\pandasstubs\lib\site-packages\pandas\core\arrays\arrow\array.py", line 443, in _box_pa_scalar
pa_scalar = pa.scalar(value, type=pa_type, from_pandas=True)
File "pyarrow\\scalar.pxi", line 1670, in pyarrow.lib.scalar
File "pyarrow\\error.pxi", line 155, in pyarrow.lib.pyarrow_internal_check_status
File "pyarrow\\error.pxi", line 92, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: Could not convert WindowsPath('c:/Code/pandas-stubs') with type WindowsPath: did not recognize Python value type when inferring an Arrow data type
While the error says something about Windows, a similar error occurs in Linux.
Expected Behavior
No exception thrown
Installed Versions
INSTALLED VERSIONS
commit : c888af6
python : 3.10.14
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.26100
machine : AMD64
processor : Intel64 Family 6 Model 183 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 2.3.1
numpy : 2.2.6
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 24.2
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.4
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : 1.1
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : 6.0.0
matplotlib : 3.10.3
numba : None
numexpr : 2.11.0
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 21.0.0
pyreadstat : 1.3.0
pytest : 8.4.1
python-calamine : None
pyxlsb : 1.0.10
s3fs : None
scipy : 1.15.3
sqlalchemy : 2.0.41
tables : 3.10.1
tabulate : 0.9.0
xarray : 2025.6.1
xlrd : 2.0.2
xlsxwriter : 3.2.5
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None