You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "MMCMA (via GitHub)" <gi...@apache.org> on 2023/03/15 14:39:06 UTC
[GitHub] [arrow] MMCMA opened a new issue, #34574: Round-trip type-conversion bug list object in pd.DataFrame
MMCMA opened a new issue, #34574:
URL: https://github.com/apache/arrow/issues/34574
### Describe the bug, including details regarding any error messages, version, and platform.
I am trying to convert a pandas DataFrame into a table and back. However the type property is lost, the list is returned as an numpy.array
```
import pandas as pd
import pyarrow as pa
df = pd.DataFrame(dict(a=[[1,2,3],]))
type(df['a'].iloc[0])
# Out[1]: list
round_trip_df = pa.Table.from_pandas(df).to_pandas()
type(round_trip_df['a'].iloc[0])
# Out[2]: numpy.ndarray
```
Here is the output of `pd.show_versions()`;
INSTALLED VERSIONS
------------------
commit : 2e218d10984e9919f0296931d92ea851c6a6faf5
python : 3.10.9.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.5.3
numpy : 1.23.5
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 64.0.2
pip : 23.0
Cython : 0.29.33
pytest : 7.2.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : 1.1
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : 8.10.0
pandas_datareader: 0.10.0
bs4 : 4.11.2
bottleneck : None
brotli :
fastparquet : None
fsspec : 2023.1.0
gcsfs : None
matplotlib : 3.7.0
numba : 0.56.4
numexpr : None
odfpy : None
openpyxl : 3.1.1
pandas_gbq : None
pyarrow : 9.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.1
snappy : None
sqlalchemy : 1.4.46
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
### Component(s)
Python
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] AlenkaF commented on issue #34574: [Python] Round-trip type-conversion bug list object in pd.DataFrame
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on issue #34574:
URL: https://github.com/apache/arrow/issues/34574#issuecomment-1477545794
If I am reading the C++ code correctly, this is the current design in the conversion of the lists
https://github.com/apache/arrow/blob/69118b2d26f2fbbbe65ad30dbe167d74b70fe791/python/pyarrow/src/arrow/python/arrow_to_pandas.cc#L735-L770
We do, however, store the `pandas_dtype` in schema metadata:
```python
>>> table = pa.Table.from_pandas(df)
>>> table.schema.metadata
{b'pandas': b'{"index_columns": [{"kind": "range", "name": null, "start": 0, "stop": 1, "step": 1}], "column_indexes": [{"name": null, "field_name": null, "pandas_type": "unicode", "numpy_type": "object", "metadata": {"encoding": "UTF-8"}}], "columns": [{"name": "a", "field_name": "a", "pandas_type": "list[int64]", ...
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org