@@ -668,29 +668,29 @@ def test_array_function_obj_tests(stmt, py_expr):
668668 assert a == b
669669
670670
671- def test_make_map ():
671+ def test_map_from_dict ():
672672 ctx = SessionContext ()
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 )
676+ result = df .select (f .map ({"x" : 1 , "y" : 2 }).alias ("m " )).collect ()[0 ].column (0 )
677677 assert result [0 ].as_py () == [("x" , 1 ), ("y" , 2 )]
678678
679679
680- def test_make_map_with_expr_values ():
680+ def test_map_from_dict_with_expr_values ():
681681 ctx = SessionContext ()
682682 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
683683 df = ctx .create_dataframe ([[batch ]])
684684
685685 result = (
686- df .select (f .make_map ({"x" : literal (1 ), "y" : literal (2 )}).alias ("map " ))
686+ df .select (f .map ({"x" : literal (1 ), "y" : literal (2 )}).alias ("m " ))
687687 .collect ()[0 ]
688688 .column (0 )
689689 )
690690 assert result [0 ].as_py () == [("x" , 1 ), ("y" , 2 )]
691691
692692
693- def test_make_map_with_column_data ():
693+ def test_map_from_two_lists ():
694694 ctx = SessionContext ()
695695 batch = pa .RecordBatch .from_arrays (
696696 [
@@ -701,7 +701,7 @@ def test_make_map_with_column_data():
701701 )
702702 df = ctx .create_dataframe ([[batch ]])
703703
704- m = f .make_map ( keys = [column ("keys" )], values = [column ("vals" )])
704+ m = f .map ( [column ("keys" )], [column ("vals" )])
705705 result = df .select (f .map_keys (m ).alias ("k" )).collect ()[0 ].column (0 )
706706 for i , expected in enumerate (["k1" , "k2" , "k3" ]):
707707 assert result [i ].as_py () == [expected ]
@@ -711,12 +711,48 @@ def test_make_map_with_column_data():
711711 assert result [i ].as_py () == [expected ]
712712
713713
714+ def test_map_from_variadic_pairs ():
715+ ctx = SessionContext ()
716+ batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
717+ df = ctx .create_dataframe ([[batch ]])
718+
719+ result = df .select (f .map ("x" , 1 , "y" , 2 ).alias ("m" )).collect ()[0 ].column (0 )
720+ assert result [0 ].as_py () == [("x" , 1 ), ("y" , 2 )]
721+
722+
723+ def test_map_variadic_with_exprs ():
724+ ctx = SessionContext ()
725+ batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
726+ df = ctx .create_dataframe ([[batch ]])
727+
728+ result = (
729+ df .select (f .map (literal ("x" ), literal (1 ), literal ("y" ), literal (2 )).alias ("m" ))
730+ .collect ()[0 ]
731+ .column (0 )
732+ )
733+ assert result [0 ].as_py () == [("x" , 1 ), ("y" , 2 )]
734+
735+
736+ def test_map_odd_args_raises ():
737+ with pytest .raises (ValueError , match = "map expects" ):
738+ f .map ("x" , 1 , "y" )
739+
740+
741+ def test_make_map_is_alias ():
742+ ctx = SessionContext ()
743+ batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
744+ df = ctx .create_dataframe ([[batch ]])
745+
746+ result = df .select (f .make_map ({"x" : 1 , "y" : 2 }).alias ("m" )).collect ()[0 ].column (0 )
747+ assert result [0 ].as_py () == [("x" , 1 ), ("y" , 2 )]
748+
749+
714750def test_map_keys ():
715751 ctx = SessionContext ()
716752 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
717753 df = ctx .create_dataframe ([[batch ]])
718754
719- m = f .make_map ({"x" : 1 , "y" : 2 })
755+ m = f .map ({"x" : 1 , "y" : 2 })
720756 result = df .select (f .map_keys (m ).alias ("keys" )).collect ()[0 ].column (0 )
721757 assert result [0 ].as_py () == ["x" , "y" ]
722758
@@ -726,7 +762,7 @@ def test_map_values():
726762 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
727763 df = ctx .create_dataframe ([[batch ]])
728764
729- m = f .make_map ({"x" : 1 , "y" : 2 })
765+ m = f .map ({"x" : 1 , "y" : 2 })
730766 result = df .select (f .map_values (m ).alias ("vals" )).collect ()[0 ].column (0 )
731767 assert result [0 ].as_py () == [1 , 2 ]
732768
@@ -736,7 +772,7 @@ def test_map_extract():
736772 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
737773 df = ctx .create_dataframe ([[batch ]])
738774
739- m = f .make_map ({"x" : 1 , "y" : 2 })
775+ m = f .map ({"x" : 1 , "y" : 2 })
740776 result = (
741777 df .select (f .map_extract (m , literal ("x" )).alias ("val" )).collect ()[0 ].column (0 )
742778 )
@@ -748,7 +784,7 @@ def test_map_extract_missing_key():
748784 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
749785 df = ctx .create_dataframe ([[batch ]])
750786
751- m = f .make_map ({"x" : 1 })
787+ m = f .map ({"x" : 1 })
752788 result = (
753789 df .select (f .map_extract (m , literal ("z" )).alias ("val" )).collect ()[0 ].column (0 )
754790 )
@@ -760,7 +796,7 @@ def test_map_entries():
760796 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
761797 df = ctx .create_dataframe ([[batch ]])
762798
763- m = f .make_map ({"x" : 1 , "y" : 2 })
799+ m = f .map ({"x" : 1 , "y" : 2 })
764800 result = df .select (f .map_entries (m ).alias ("entries" )).collect ()[0 ].column (0 )
765801 assert result [0 ].as_py () == [
766802 {"key" : "x" , "value" : 1 },
@@ -773,7 +809,7 @@ def test_element_at():
773809 batch = pa .RecordBatch .from_arrays ([pa .array ([1 ])], names = ["a" ])
774810 df = ctx .create_dataframe ([[batch ]])
775811
776- m = f .make_map ({"a" : 10 , "b" : 20 })
812+ m = f .map ({"a" : 10 , "b" : 20 })
777813 result = (
778814 df .select (f .element_at (m , literal ("b" )).alias ("val" )).collect ()[0 ].column (0 )
779815 )
0 commit comments