@@ -1383,10 +1383,8 @@ def process_args_into_dataframe(
1383
1383
% (field , len_arg , str (list (df_output .keys ())), length )
1384
1384
)
1385
1385
1386
- # With `pass_through=True`, the original object will be returned if unable to convert
1387
- # to a Narwhals Series.
1388
1386
df_output [str (col_name )] = to_unindexed_series (
1389
- x = nw . from_native ( argument , series_only = True , pass_through = True ) ,
1387
+ x = argument ,
1390
1388
name = str (col_name ),
1391
1389
native_namespace = native_namespace ,
1392
1390
)
@@ -1418,14 +1416,15 @@ def process_args_into_dataframe(
1418
1416
msg = "Pandas installation is required if no dataframe is provided."
1419
1417
raise NotImplementedError (msg )
1420
1418
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
+ )
1429
1428
1430
1429
df_output .update (
1431
1430
{
@@ -2159,7 +2158,7 @@ def process_dataframe_pie(args, trace_patch):
2159
2158
df : nw .DataFrame = args ["data_frame" ]
2160
2159
trace_patch ["sort" ] = False
2161
2160
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 ()
2163
2162
order = [x for x in OrderedDict .fromkeys (list (order_in ) + uniques ) if x in uniques ]
2164
2163
2165
2164
# Original implementation: args["data_frame"] = df.set_index(names).loc[order].reset_index()
@@ -2422,7 +2421,9 @@ def get_groups_and_orders(args, grouper):
2422
2421
single_group_name .append ("" )
2423
2422
else :
2424
2423
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
+ )
2426
2427
uniques = unique_cache [col ]
2427
2428
if len (uniques ) == 1 :
2428
2429
single_group_name .append (uniques [0 ])
0 commit comments