@@ -604,6 +604,37 @@ def test_uuid_extension_type():
604604 store_schema = False )
605605
606606
607+ @pytest .mark .pandas
608+ def test_uuid_roundtrip (tempdir ):
609+ import uuid
610+ u1 , u2 = uuid .uuid4 (), uuid .uuid4 ()
611+ df = pd .DataFrame ({"id" : [u1 , None , u2 ]})
612+ table = pa .Table .from_pandas (df )
613+ assert table .column ("id" ).type == pa .uuid ()
614+
615+ path = tempdir / "uuid_pandas_roundtrip.parquet"
616+ pq .write_table (table , path )
617+ read_table = pq .read_table (path )
618+ assert read_table .column ("id" ).type == pa .uuid ()
619+
620+ result_df = read_table .to_pandas ()
621+ assert isinstance (result_df .loc [0 , "id" ], uuid .UUID )
622+ assert isinstance (result_df .loc [2 , "id" ], uuid .UUID )
623+ assert result_df .loc [0 , "id" ] == u1
624+ assert result_df .loc [2 , "id" ] == u2
625+ assert pd .isna (result_df .loc [1 , "id" ])
626+
627+ @pytest .mark .pandas
628+ def test_uuid_array_to_pandas ():
629+ from uuid import uuid4
630+ import pandas as pd
631+ import pandas .testing as tm
632+ values = [uuid4 (), None , uuid4 ()]
633+ arr = pa .array (values , type = pa .uuid ())
634+ result = arr .to_pandas ()
635+ expected = pd .Series (values , dtype = object )
636+ tm .assert_series_equal (result , expected )
637+
607638def test_undefined_logical_type (parquet_test_datadir ):
608639 test_file = f"{ parquet_test_datadir } /unknown-logical-type.parquet"
609640
0 commit comments