sohailshk opened a new issue, #55677:
URL: https://github.com/apache/arrow/issues/55677

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   The pandas metadata written by `Table.from_pandas` records the extension 
dtype of an index level (`numpy_type: "Int64"`), and `to_pandas` uses it for 
data columns, but not for index levels. The index comes back with the default 
dtype for the Arrow type, and a nullable integer index with missing values 
turns into a float index.
   
   ```python
   import pandas as pd
   import pyarrow as pa
   
   df = pd.DataFrame({"a": [1, 2, 3]}, index=pd.Index(pd.array([1, None, 3], 
dtype="Int64"), name="idx"))
   table = pa.Table.from_pandas(df)
   print(table.schema.pandas_metadata["columns"][-1]["numpy_type"])   # Int64
   print(table.to_pandas().index)
   ```
   
   Result (integers above 2**53 also lose precision in the float conversion): 
`Index([1.0, nan, 3.0], dtype='float64', name='idx')`. Expected: `Index([1, 
<NA>, 3], dtype='Int64', name='idx')`.
   
   The same happens for `Int8`...`UInt64`, `Float32/64`, `boolean`, `string`, 
and `pd.ArrowDtype` indexes (`int64[pyarrow]` becomes `int64` without nulls and 
`float64` with nulls), for MultiIndex levels, and through `df.to_parquet` / 
`pd.read_parquet`.
   
   Reproduced with pyarrow 26.0.1 + pandas 3.1.1 and + pandas 2.3.3, and with 
pyarrow 18.1.0 + pandas 2.2.3 (Python 3.13, macOS arm64), so this is 
long-standing, not a regression. `_extract_index_level` in `pandas_compat.py` 
is unchanged on current main.
   
   Related: #31031 (IntervalIndex, now restored through the Arrow extension 
type) and #34283 (`types_mapper` for the index). Dtypes stored as plain Arrow 
types, like the ones above, are still not restored.
   
   ### 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to