@@ -673,32 +673,50 @@ def test_make_map():
673673 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
674674 df = ctx .create_dataframe ([[batch ]])
675675
676+ result = df .select (f .make_map ({"x" : 1 , "y" : 2 }).alias ("map" )).collect ()[0 ].column (0 )
677+ assert result [0 ].as_py () == [("x" , 1 ), ("y" , 2 )]
678+
679+
680+ def test_make_map_with_expr_values ():
681+ ctx = SessionContext ()
682+ batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
683+ df = ctx .create_dataframe ([[batch ]])
684+
676685 result = (
677- df .select (
678- f .make_map (
679- literal ("x" ),
680- literal (1 ),
681- literal ("y" ),
682- literal (2 ),
683- ).alias ("map" )
684- )
686+ df .select (f .make_map ({"x" : literal (1 ), "y" : literal (2 )}).alias ("map" ))
685687 .collect ()[0 ]
686688 .column (0 )
687689 )
688690 assert result [0 ].as_py () == [("x" , 1 ), ("y" , 2 )]
689691
690692
691- def test_make_map_odd_args ():
692- with pytest .raises (ValueError , match = "even number of arguments" ):
693- f .make_map (literal ("x" ), literal (1 ), literal ("y" ))
693+ def test_make_map_with_column_data ():
694+ ctx = SessionContext ()
695+ batch = pa .RecordBatch .from_arrays (
696+ [
697+ pa .array (["k1" , "k2" , "k3" ]),
698+ pa .array ([10 , 20 , 30 ]),
699+ ],
700+ names = ["keys" , "vals" ],
701+ )
702+ df = ctx .create_dataframe ([[batch ]])
703+
704+ m = f .make_map (keys = [column ("keys" )], values = [column ("vals" )])
705+ result = df .select (f .map_keys (m ).alias ("k" )).collect ()[0 ].column (0 )
706+ for i , expected in enumerate (["k1" , "k2" , "k3" ]):
707+ assert result [i ].as_py () == [expected ]
708+
709+ result = df .select (f .map_values (m ).alias ("v" )).collect ()[0 ].column (0 )
710+ for i , expected in enumerate ([10 , 20 , 30 ]):
711+ assert result [i ].as_py () == [expected ]
694712
695713
696714def test_map_keys ():
697715 ctx = SessionContext ()
698716 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
699717 df = ctx .create_dataframe ([[batch ]])
700718
701- m = f .make_map (literal ( "x" ), literal ( 1 ), literal ( "y" ), literal ( 2 ) )
719+ m = f .make_map ({ "x" : 1 , "y" : 2 } )
702720 result = df .select (f .map_keys (m ).alias ("keys" )).collect ()[0 ].column (0 )
703721 assert result [0 ].as_py () == ["x" , "y" ]
704722
@@ -708,7 +726,7 @@ def test_map_values():
708726 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
709727 df = ctx .create_dataframe ([[batch ]])
710728
711- m = f .make_map (literal ( "x" ), literal ( 1 ), literal ( "y" ), literal ( 2 ) )
729+ m = f .make_map ({ "x" : 1 , "y" : 2 } )
712730 result = df .select (f .map_values (m ).alias ("vals" )).collect ()[0 ].column (0 )
713731 assert result [0 ].as_py () == [1 , 2 ]
714732
@@ -718,7 +736,7 @@ def test_map_extract():
718736 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
719737 df = ctx .create_dataframe ([[batch ]])
720738
721- m = f .make_map (literal ( "x" ), literal ( 1 ), literal ( "y" ), literal ( 2 ) )
739+ m = f .make_map ({ "x" : 1 , "y" : 2 } )
722740 result = (
723741 df .select (f .map_extract (m , literal ("x" )).alias ("val" )).collect ()[0 ].column (0 )
724742 )
@@ -730,7 +748,7 @@ def test_map_extract_missing_key():
730748 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
731749 df = ctx .create_dataframe ([[batch ]])
732750
733- m = f .make_map (literal ( "x" ), literal ( 1 ) )
751+ m = f .make_map ({ "x" : 1 } )
734752 result = (
735753 df .select (f .map_extract (m , literal ("z" )).alias ("val" )).collect ()[0 ].column (0 )
736754 )
@@ -742,7 +760,7 @@ def test_map_entries():
742760 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
743761 df = ctx .create_dataframe ([[batch ]])
744762
745- m = f .make_map (literal ( "x" ), literal ( 1 ), literal ( "y" ), literal ( 2 ) )
763+ m = f .make_map ({ "x" : 1 , "y" : 2 } )
746764 result = df .select (f .map_entries (m ).alias ("entries" )).collect ()[0 ].column (0 )
747765 assert result [0 ].as_py () == [
748766 {"key" : "x" , "value" : 1 },
@@ -755,34 +773,13 @@ def test_element_at():
755773 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
756774 df = ctx .create_dataframe ([[batch ]])
757775
758- m = f .make_map (literal ( "a" ), literal ( 10 ), literal ( "b" ), literal ( 20 ) )
776+ m = f .make_map ({ "a" : 10 , "b" : 20 } )
759777 result = (
760778 df .select (f .element_at (m , literal ("b" )).alias ("val" )).collect ()[0 ].column (0 )
761779 )
762780 assert result [0 ].as_py () == [20 ]
763781
764782
765- def test_map_functions_with_column_data ():
766- ctx = SessionContext ()
767- batch = pa .RecordBatch .from_arrays (
768- [
769- pa .array (["k1" , "k2" , "k3" ]),
770- pa .array ([10 , 20 , 30 ]),
771- ],
772- names = ["keys" , "vals" ],
773- )
774- df = ctx .create_dataframe ([[batch ]])
775-
776- m = f .make_map (column ("keys" ), column ("vals" ))
777- result = df .select (f .map_keys (m ).alias ("k" )).collect ()[0 ].column (0 )
778- for i , expected in enumerate (["k1" , "k2" , "k3" ]):
779- assert result [i ].as_py () == [expected ]
780-
781- result = df .select (f .map_values (m ).alias ("v" )).collect ()[0 ].column (0 )
782- for i , expected in enumerate ([10 , 20 , 30 ]):
783- assert result [i ].as_py () == [expected ]
784-
785-
786783@pytest .mark .parametrize (
787784 ("function" , "expected_result" ),
788785 [
0 commit comments