@@ -110,12 +110,7 @@ bench -n 10 --pretty {
110110 | math sum
111111 }
112112}
113- ```
114-
115- Output
116-
117- ```
118- 3sec 268ms +/- 50ms
113+ # => 3sec 268ms +/- 50ms
119114```
120115
121116So, 3.3 seconds to perform this aggregation.
@@ -137,12 +132,7 @@ And the result from the benchmark is:
137132bench -n 10 --pretty {
138133 python load.py | complete | null
139134}
140- ```
141-
142- Output
143-
144- ```
145- 1sec 322ms +/- 6ms
135+ # => 1sec 322ms +/- 6ms
146136```
147137
148138Not bad at all. Pandas managed to get it 2.6 times faster than Nushell.
@@ -167,12 +157,7 @@ instance for each test in order of honest comparison) is:
167157bench -n 10 --pretty {
168158 nu load.nu | complete | null
169159}
170- ```
171-
172- Output
173-
174- ```
175- 135ms +/- 4ms
160+ # => 135ms +/- 4ms
176161```
177162
178163The ` polars ` dataframes plugin managed to finish operation 10 times
@@ -437,25 +422,20 @@ $group
437422 (polars col float_1 | polars sum)
438423 (polars col float_2 | polars count)
439424] | polars sort-by first
440- ```
441-
442- Output
443-
444- ```
445- ╭────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────╮
446- │ plan │ SORT BY [col("first")] │
447- │ │ AGGREGATE │
448- │ │ [col("int_1").n_unique(), col("int_2").min(), col("float_1") │
449- │ │ .sum(), col("float_2").count()] BY [col("first")] FROM │
450- │ │ DF ["int_1", "int_2", "float_1", "float_2 │
451- │ │ "]; PROJECT */8 COLUMNS; SELECTION: "None" │
452- │ optimized_plan │ SORT BY [col("first")] │
453- │ │ AGGREGATE │
454- │ │ [col("int_1").n_unique(), col("int_2").min(), col("float_1") │
455- │ │ .sum(), col("float_2").count()] BY [col("first")] FROM │
456- │ │ DF ["int_1", "int_2", "float_1", "float_2 │
457- │ │ "]; PROJECT 5/8 COLUMNS; SELECTION: "None" │
458- ╰────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────╯
425+ # => ╭────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────╮
426+ # => │ plan │ SORT BY [col("first")] │
427+ # => │ │ AGGREGATE │
428+ # => │ │ [col("int_1").n_unique(), col("int_2").min(), col("float_1") │
429+ # => │ │ .sum(), col("float_2").count()] BY [col("first")] FROM │
430+ # => │ │ DF ["int_1", "int_2", "float_1", "float_2 │
431+ # => │ │ "]; PROJECT */8 COLUMNS; SELECTION: "None" │
432+ # => │ optimized_plan │ SORT BY [col("first")] │
433+ # => │ │ AGGREGATE │
434+ # => │ │ [col("int_1").n_unique(), col("int_2").min(), col("float_1") │
435+ # => │ │ .sum(), col("float_2").count()] BY [col("first")] FROM │
436+ # => │ │ DF ["int_1", "int_2", "float_1", "float_2 │
437+ # => │ │ "]; PROJECT 5/8 COLUMNS; SELECTION: "None" │
438+ # => ╰────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────╯
459439```
460440
461441As you can see, the ` GroupBy ` object is a very powerful variable and it is
@@ -902,40 +882,30 @@ in column `word`
902882
903883``` nu
904884$df_1 | polars filter-with ($in.word | polars is-unique)
905- ```
906-
907- Output
908-
909- ```
910- ╭───┬───────┬───────┬─────────┬─────────┬───────┬────────┬───────┬───────╮
911- │ # │ int_1 │ int_2 │ float_1 │ float_2 │ first │ second │ third │ word │
912- ├───┼───────┼───────┼─────────┼─────────┼───────┼────────┼───────┼───────┤
913- │ 0 │ 1 │ 11 │ 0.10 │ 1.00 │ a │ b │ c │ first │
914- │ 1 │ 8 │ 18 │ 0.80 │ 7.00 │ c │ c │ b │ eight │
915- ╰───┴───────┴───────┴─────────┴─────────┴───────┴────────┴───────┴───────╯
885+ # => ╭───┬───────┬───────┬─────────┬─────────┬───────┬────────┬───────┬───────╮
886+ # => │ # │ int_1 │ int_2 │ float_1 │ float_2 │ first │ second │ third │ word │
887+ # => ├───┼───────┼───────┼─────────┼─────────┼───────┼────────┼───────┼───────┤
888+ # => │ 0 │ 1 │ 11 │ 0.10 │ 1.00 │ a │ b │ c │ first │
889+ # => │ 1 │ 8 │ 18 │ 0.80 │ 7.00 │ c │ c │ b │ eight │
890+ # => ╰───┴───────┴───────┴─────────┴─────────┴───────┴────────┴───────┴───────╯
916891```
917892
918893Or all the duplicated ones
919894
920895``` nu
921896$df_1 | polars filter-with ($in.word | polars is-duplicated)
922- ```
923-
924- Output
925-
926- ```
927- ╭───┬───────┬───────┬─────────┬─────────┬───────┬────────┬───────┬────────╮
928- │ # │ int_1 │ int_2 │ float_1 │ float_2 │ first │ second │ third │ word │
929- ├───┼───────┼───────┼─────────┼─────────┼───────┼────────┼───────┼────────┤
930- │ 0 │ 2 │ 12 │ 0.20 │ 1.00 │ a │ b │ c │ second │
931- │ 1 │ 3 │ 13 │ 0.30 │ 2.00 │ a │ b │ c │ third │
932- │ 2 │ 4 │ 14 │ 0.40 │ 3.00 │ b │ a │ c │ second │
933- │ 3 │ 0 │ 15 │ 0.50 │ 4.00 │ b │ a │ a │ third │
934- │ 4 │ 6 │ 16 │ 0.60 │ 5.00 │ b │ a │ a │ second │
935- │ 5 │ 7 │ 17 │ 0.70 │ 6.00 │ b │ c │ a │ third │
936- │ 6 │ 9 │ 19 │ 0.90 │ 8.00 │ c │ c │ b │ ninth │
937- │ 7 │ 0 │ 10 │ 0.00 │ 9.00 │ c │ c │ b │ ninth │
938- ╰───┴───────┴───────┴─────────┴─────────┴───────┴────────┴───────┴────────╯
897+ # => ╭───┬───────┬───────┬─────────┬─────────┬───────┬────────┬───────┬────────╮
898+ # => │ # │ int_1 │ int_2 │ float_1 │ float_2 │ first │ second │ third │ word │
899+ # => ├───┼───────┼───────┼─────────┼─────────┼───────┼────────┼───────┼────────┤
900+ # => │ 0 │ 2 │ 12 │ 0.20 │ 1.00 │ a │ b │ c │ second │
901+ # => │ 1 │ 3 │ 13 │ 0.30 │ 2.00 │ a │ b │ c │ third │
902+ # => │ 2 │ 4 │ 14 │ 0.40 │ 3.00 │ b │ a │ c │ second │
903+ # => │ 3 │ 0 │ 15 │ 0.50 │ 4.00 │ b │ a │ a │ third │
904+ # => │ 4 │ 6 │ 16 │ 0.60 │ 5.00 │ b │ a │ a │ second │
905+ # => │ 5 │ 7 │ 17 │ 0.70 │ 6.00 │ b │ c │ a │ third │
906+ # => │ 6 │ 9 │ 19 │ 0.90 │ 8.00 │ c │ c │ b │ ninth │
907+ # => │ 7 │ 0 │ 10 │ 0.00 │ 9.00 │ c │ c │ b │ ninth │
908+ # => ╰───┴───────┴───────┴─────────┴─────────┴───────┴────────┴───────┴────────╯
939909```
940910
941911## Lazy Dataframes
@@ -998,19 +968,14 @@ $lf_0
998968 ((polars col a) / 2 | polars as half_a)
999969]
1000970| polars collect
1001- ```
1002-
1003- Output
1004-
1005- ```
1006- ╭───┬───┬───┬──────────┬────────╮
1007- │ # │ a │ b │ double_a │ half_a │
1008- ├───┼───┼───┼──────────┼────────┤
1009- │ 0 │ 4 │ d │ 8 │ 2 │
1010- │ 1 │ 3 │ c │ 6 │ 1 │
1011- │ 2 │ 2 │ b │ 4 │ 1 │
1012- │ 3 │ 1 │ a │ 2 │ 0 │
1013- ╰───┴───┴───┴──────────┴────────╯
971+ # => ╭───┬───┬───┬──────────┬────────╮
972+ # => │ # │ a │ b │ double_a │ half_a │
973+ # => ├───┼───┼───┼──────────┼────────┤
974+ # => │ 0 │ 4 │ d │ 8 │ 2 │
975+ # => │ 1 │ 3 │ c │ 6 │ 1 │
976+ # => │ 2 │ 2 │ b │ 4 │ 1 │
977+ # => │ 3 │ 1 │ a │ 2 │ 0 │
978+ # => ╰───┴───┴───┴──────────┴────────╯
1014979```
1015980
1016981::: tip
@@ -1072,17 +1037,12 @@ $lf_1
10721037 (polars col value | polars mean | polars as mean)
10731038]
10741039| polars collect
1075- ```
1076-
1077- Output
1078-
1079- ```
1080- ╭───┬──────┬─────┬──────╮
1081- │ # │ name │ sum │ mean │
1082- ├───┼──────┼─────┼──────┤
1083- │ 0 │ two │ 5 │ 2.50 │
1084- │ 1 │ one │ 2 │ 1.00 │
1085- ╰───┴──────┴─────┴──────╯
1040+ # => ╭───┬──────┬─────┬──────╮
1041+ # => │ # │ name │ sum │ mean │
1042+ # => ├───┼──────┼─────┼──────┤
1043+ # => │ 0 │ two │ 5 │ 2.50 │
1044+ # => │ 1 │ one │ 2 │ 1.00 │
1045+ # => ╰───┴──────┴─────┴──────╯
10861046```
10871047
10881048And we could join on a lazy dataframe that hasn't being collected. Let's join
@@ -1098,19 +1058,14 @@ let group = $lf_2
10981058 ]
10991059
11001060$lf_2 | polars join $group name name | polars collect
1101- ```
1102-
1103- Output
1104-
1105- ```
1106- ╭───┬──────┬───────┬─────┬──────╮
1107- │ # │ name │ value │ sum │ mean │
1108- ├───┼──────┼───────┼─────┼──────┤
1109- │ 0 │ one │ 1 │ 2 │ 1.00 │
1110- │ 1 │ two │ 2 │ 5 │ 2.50 │
1111- │ 2 │ one │ 1 │ 2 │ 1.00 │
1112- │ 3 │ two │ 3 │ 5 │ 2.50 │
1113- ╰───┴──────┴───────┴─────┴──────╯
1061+ # => ╭───┬──────┬───────┬─────┬──────╮
1062+ # => │ # │ name │ value │ sum │ mean │
1063+ # => ├───┼──────┼───────┼─────┼──────┤
1064+ # => │ 0 │ one │ 1 │ 2 │ 1.00 │
1065+ # => │ 1 │ two │ 2 │ 5 │ 2.50 │
1066+ # => │ 2 │ one │ 1 │ 2 │ 1.00 │
1067+ # => │ 3 │ two │ 3 │ 5 │ 2.50 │
1068+ # => ╰───┴──────┴───────┴─────┴──────╯
11141069```
11151070
11161071As you can see lazy frames are a powerful construct that will let you query
0 commit comments