@@ -604,6 +604,39 @@ 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+
628+ @pytest .mark .pandas
629+ def test_uuid_array_to_pandas ():
630+ from uuid import uuid4
631+ import pandas as pd
632+ import pandas .testing as tm
633+ values = [uuid4 (), None , uuid4 ()]
634+ arr = pa .array (values , type = pa .uuid ())
635+ result = arr .to_pandas ()
636+ expected = pd .Series (values , dtype = object )
637+ tm .assert_series_equal (result , expected )
638+
639+
607640def test_undefined_logical_type (parquet_test_datadir ):
608641 test_file = f"{ parquet_test_datadir } /unknown-logical-type.parquet"
609642
0 commit comments