@@ -626,6 +626,38 @@ def test_chunked_list_struct_array():
626
626
assert ext_array .chunked_list_struct_array .type == ext_array ._pyarrow_list_struct_dtype
627
627
628
628
629
+ def test_to_pyarrow_scalar ():
630
+ """Test .to_pyarrow_scalar is correct."""
631
+ struct_array = pa .StructArray .from_arrays (
632
+ arrays = [
633
+ pa .array ([np .array ([1 , 2 , 3 ]), np .array ([1 , 2 , 1 ])]),
634
+ pa .array ([- np .array ([4.0 , 5.0 , 6.0 ]), - np .array ([3.0 , 4.0 , 5.0 ])]),
635
+ ],
636
+ names = ["a" , "b" ],
637
+ )
638
+ ext_array = NestedExtensionArray (struct_array )
639
+
640
+ desired_struct_list = pa .scalar (
641
+ [
642
+ {"a" : [1 , 2 , 3 ], "b" : [- 4.0 , - 5.0 , - 6.0 ]},
643
+ {"a" : [1 , 2 , 1 ], "b" : [- 3.0 , - 4.0 , - 5.0 ]},
644
+ ],
645
+ type = pa .list_ (
646
+ pa .struct ([pa .field ("a" , pa .list_ (pa .int64 ())), pa .field ("b" , pa .list_ (pa .float64 ()))])
647
+ ),
648
+ )
649
+ desired_list_struct = pa .scalar (
650
+ [
651
+ [{"a" : 1 , "b" : - 4.0 }, {"a" : 2 , "b" : - 5.0 }, {"a" : 3 , "b" : - 6.0 }],
652
+ [{"a" : 1 , "b" : - 3.0 }, {"a" : 2 , "b" : - 4.0 }, {"a" : 1 , "b" : - 5.0 }],
653
+ ],
654
+ type = pa .list_ (pa .list_ (pa .struct ([pa .field ("a" , pa .int64 ()), pa .field ("b" , pa .float64 ())]))),
655
+ )
656
+ # pyarrow returns a single bool for ==
657
+ assert ext_array .to_pyarrow_scalar (list_struct = False ) == desired_struct_list
658
+ assert ext_array .to_pyarrow_scalar (list_struct = True ) == desired_list_struct
659
+
660
+
629
661
def test_list_offsets_single_chunk ():
630
662
"""Test that the .list_offset property is correct for a single chunk."""
631
663
struct_array = pa .StructArray .from_arrays (
0 commit comments