Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
bretttully authored Nov 13, 2024
1 parent 1e8d4b7 commit cb87068
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions python/pyarrow/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import gc
import decimal
import io
import json
import multiprocessing as mp
import sys
Expand Down Expand Up @@ -4411,6 +4412,31 @@ def test_to_pandas_extension_dtypes_mapping():
assert isinstance(result['a'].dtype, pd.PeriodDtype)



def test_to_pandas_extension_dtypes_mapping_complex_type():
pa_type = pa.struct(
[
pa.field("bar", pa.bool_(), nullable=False),
pa.field("baz", pa.float32(), nullable=True),
],
)
pd_type = pd.ArrowDtype(pa_type)
schema = pa.schema([pa.field("foo", pa_type)])
df0 = pd.DataFrame(
[
{"foo": {"bar": True, "baz": np.float32(1)}},
{"foo": {"bar": True, "baz": None}},
],
).astype({"foo": pd_type})

# Round trip df0 into df1
with io.BytesIO() as stream:
df0.to_parquet(stream, schema=schema)
stream.seek(0)
df1 = pd.read_parquet(stream, dtype_backend="pyarrow")
pd.testing.assert_frame_equal(df0, df1)


def test_array_to_pandas():
if Version(pd.__version__) < Version("1.1"):
pytest.skip("ExtensionDtype to_pandas method missing")
Expand Down

0 comments on commit cb87068

Please sign in to comment.