@@ -1383,10 +1383,8 @@ def process_args_into_dataframe(
13831383 % (field , len_arg , str (list (df_output .keys ())), length )
13841384 )
13851385
1386- # With `pass_through=True`, the original object will be returned if unable to convert
1387- # to a Narwhals Series.
13881386 df_output [str (col_name )] = to_unindexed_series (
1389- x = nw . from_native ( argument , series_only = True , pass_through = True ) ,
1387+ x = argument ,
13901388 name = str (col_name ),
13911389 native_namespace = native_namespace ,
13921390 )
@@ -1418,14 +1416,15 @@ def process_args_into_dataframe(
14181416 msg = "Pandas installation is required if no dataframe is provided."
14191417 raise NotImplementedError (msg )
14201418
1421- df_output .update (
1422- {
1423- col_name : nw .new_series (
1424- name = col_name , values = range (length ), native_namespace = native_namespace
1425- )
1426- for col_name in ranges
1427- }
1428- )
1419+ if ranges :
1420+ range_series = nw .new_series (
1421+ name = "__placeholder__" ,
1422+ values = range (length ),
1423+ native_namespace = native_namespace ,
1424+ )
1425+ df_output .update (
1426+ {col_name : range_series .alias (col_name ) for col_name in ranges }
1427+ )
14291428
14301429 df_output .update (
14311430 {
@@ -2159,7 +2158,7 @@ def process_dataframe_pie(args, trace_patch):
21592158 df : nw .DataFrame = args ["data_frame" ]
21602159 trace_patch ["sort" ] = False
21612160 trace_patch ["direction" ] = "clockwise"
2162- uniques = df .get_column (names ).unique ().to_list ()
2161+ uniques = df .get_column (names ).unique (maintain_order = True ).to_list ()
21632162 order = [x for x in OrderedDict .fromkeys (list (order_in ) + uniques ) if x in uniques ]
21642163
21652164 # Original implementation: args["data_frame"] = df.set_index(names).loc[order].reset_index()
@@ -2422,7 +2421,9 @@ def get_groups_and_orders(args, grouper):
24222421 single_group_name .append ("" )
24232422 else :
24242423 if col not in unique_cache :
2425- unique_cache [col ] = df .get_column (col ).unique ().to_list ()
2424+ unique_cache [col ] = (
2425+ df .get_column (col ).unique (maintain_order = True ).to_list ()
2426+ )
24262427 uniques = unique_cache [col ]
24272428 if len (uniques ) == 1 :
24282429 single_group_name .append (uniques [0 ])
0 commit comments