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 pandas as pd
>>> import pyarrow as pa
>>> pa.Array.from_pandas(pd.Series([], dtype=pd.ArrowDtype(pa.timestamp('s')))) # correct
<pyarrow.lib.TimestampArray object at 0x7fb665f77fa0>
[]
>>> pa.Array.from_pandas(pd.Series([], dtype=pd.ArrowDtype(pa.timestamp('s'))).dt.tz_localize('UTC')) # incorrect
<pyarrow.lib.ChunkedArray object at 0x7fb665fd8680>
[
]
Same issue with pa.array()
instead of pa.Array.from_pandas()
. The Arrow folks say it's a pandas issue.
Issue Description
pyarrow.Array.from_pandas
converts an empty timestamp[s][pyarrow, UTC]
pandas Series to a ChunkedArray
, not a TimestampArray
. It correctly converts to a TimestampArray
when there is no timezone.
Expected Behavior
>>> import pandas as pd
>>> import pyarrow as pa
>>> pa.Array.from_pandas(pd.Series([], dtype=pd.ArrowDtype(pa.timestamp('s'))))
<pyarrow.lib.TimestampArray object at 0x7fb665f77fa0>
[]
>>> pa.Array.from_pandas(pd.Series([], dtype=pd.ArrowDtype(pa.timestamp('s'))).dt.tz_localize('UTC'))
<pyarrow.lib.TimestampArray object at 0x7fb665fd8680>
[]
Installed Versions
INSTALLED VERSIONS
commit : f538741
python : 3.12.2.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-22621-Microsoft
Version : #2506-Microsoft Fri Jan 01 08:00:00 PST 2016
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : C.UTF-8
pandas : 2.2.0
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 69.1.0
pip : 24.0
Cython : 3.0.8
pytest : 8.0.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.1.9
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 8.21.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.3
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 14.0.2
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.12.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : 0.22.0
tzdata : 2024.1
qtpy : None
pyqt5 : None