polars-df 0.2.4-x86_64-linux → 0.3.0-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/Cargo.lock +290 -137
- data/Cargo.toml +1 -1
- data/LICENSE-THIRD-PARTY.txt +1593 -979
- data/README.md +3 -3
- data/lib/polars/3.0/polars.so +0 -0
- data/lib/polars/3.1/polars.so +0 -0
- data/lib/polars/3.2/polars.so +0 -0
- data/lib/polars/batched_csv_reader.rb +1 -1
- data/lib/polars/cat_expr.rb +0 -4
- data/lib/polars/cat_name_space.rb +0 -4
- data/lib/polars/convert.rb +0 -7
- data/lib/polars/data_frame.rb +184 -217
- data/lib/polars/date_time_expr.rb +19 -151
- data/lib/polars/date_time_name_space.rb +17 -17
- data/lib/polars/expr.rb +68 -315
- data/lib/polars/group_by.rb +68 -51
- data/lib/polars/io.rb +7 -7
- data/lib/polars/lazy_frame.rb +4 -106
- data/lib/polars/lazy_functions.rb +14 -40
- data/lib/polars/lazy_group_by.rb +0 -8
- data/lib/polars/list_expr.rb +5 -27
- data/lib/polars/list_name_space.rb +5 -8
- data/lib/polars/series.rb +20 -16
- data/lib/polars/string_expr.rb +20 -76
- data/lib/polars/string_name_space.rb +5 -15
- data/lib/polars/struct_expr.rb +0 -2
- data/lib/polars/utils.rb +8 -0
- data/lib/polars/version.rb +1 -1
- metadata +2 -2
data/lib/polars/data_frame.rb
CHANGED
@@ -94,7 +94,7 @@ module Polars
|
|
94
94
|
sample_size: 1024,
|
95
95
|
eol_char: "\n"
|
96
96
|
)
|
97
|
-
if
|
97
|
+
if Utils.pathlike?(file)
|
98
98
|
path = Utils.format_path(file)
|
99
99
|
else
|
100
100
|
path = nil
|
@@ -124,7 +124,39 @@ module Polars
|
|
124
124
|
columns = [columns]
|
125
125
|
end
|
126
126
|
if file.is_a?(String) && file.include?("*")
|
127
|
-
|
127
|
+
dtypes_dict = nil
|
128
|
+
if !dtype_list.nil?
|
129
|
+
dtypes_dict = dtype_list.to_h
|
130
|
+
end
|
131
|
+
if !dtype_slice.nil?
|
132
|
+
raise ArgumentError, "cannot use glob patterns and unnamed dtypes as `dtypes` argument; Use dtypes: Mapping[str, Type[DataType]"
|
133
|
+
end
|
134
|
+
scan = Polars.scan_csv(
|
135
|
+
file,
|
136
|
+
has_header: has_header,
|
137
|
+
sep: sep,
|
138
|
+
comment_char: comment_char,
|
139
|
+
quote_char: quote_char,
|
140
|
+
skip_rows: skip_rows,
|
141
|
+
dtypes: dtypes_dict,
|
142
|
+
null_values: null_values,
|
143
|
+
ignore_errors: ignore_errors,
|
144
|
+
infer_schema_length: infer_schema_length,
|
145
|
+
n_rows: n_rows,
|
146
|
+
low_memory: low_memory,
|
147
|
+
rechunk: rechunk,
|
148
|
+
skip_rows_after_header: skip_rows_after_header,
|
149
|
+
row_count_name: row_count_name,
|
150
|
+
row_count_offset: row_count_offset,
|
151
|
+
eol_char: eol_char
|
152
|
+
)
|
153
|
+
if columns.nil?
|
154
|
+
return _from_rbdf(scan.collect._df)
|
155
|
+
elsif is_str_sequence(columns, allow_str: false)
|
156
|
+
return _from_rbdf(scan.select(columns).collect._df)
|
157
|
+
else
|
158
|
+
raise ArgumentError, "cannot use glob patterns and integer based projection as `columns` argument; Use columns: List[str]"
|
159
|
+
end
|
128
160
|
end
|
129
161
|
|
130
162
|
projection, columns = Utils.handle_projection_columns(columns)
|
@@ -170,7 +202,7 @@ module Polars
|
|
170
202
|
row_count_offset: 0,
|
171
203
|
low_memory: false
|
172
204
|
)
|
173
|
-
if
|
205
|
+
if Utils.pathlike?(file)
|
174
206
|
file = Utils.format_path(file)
|
175
207
|
end
|
176
208
|
|
@@ -194,7 +226,7 @@ module Polars
|
|
194
226
|
|
195
227
|
# @private
|
196
228
|
def self._read_avro(file, columns: nil, n_rows: nil)
|
197
|
-
if
|
229
|
+
if Utils.pathlike?(file)
|
198
230
|
file = Utils.format_path(file)
|
199
231
|
end
|
200
232
|
projection, columns = Utils.handle_projection_columns(columns)
|
@@ -211,7 +243,7 @@ module Polars
|
|
211
243
|
rechunk: true,
|
212
244
|
memory_map: true
|
213
245
|
)
|
214
|
-
if
|
246
|
+
if Utils.pathlike?(file)
|
215
247
|
file = Utils.format_path(file)
|
216
248
|
end
|
217
249
|
if columns.is_a?(String)
|
@@ -237,7 +269,7 @@ module Polars
|
|
237
269
|
|
238
270
|
# @private
|
239
271
|
def self._read_json(file)
|
240
|
-
if
|
272
|
+
if Utils.pathlike?(file)
|
241
273
|
file = Utils.format_path(file)
|
242
274
|
end
|
243
275
|
|
@@ -246,7 +278,7 @@ module Polars
|
|
246
278
|
|
247
279
|
# @private
|
248
280
|
def self._read_ndjson(file)
|
249
|
-
if
|
281
|
+
if Utils.pathlike?(file)
|
250
282
|
file = Utils.format_path(file)
|
251
283
|
end
|
252
284
|
|
@@ -335,9 +367,7 @@ module Polars
|
|
335
367
|
# # │ i64 ┆ i64 ┆ str │
|
336
368
|
# # ╞═══════╪════════╪════════╡
|
337
369
|
# # │ 1 ┆ 6 ┆ a │
|
338
|
-
# # ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
339
370
|
# # │ 2 ┆ 7 ┆ b │
|
340
|
-
# # ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
341
371
|
# # │ 3 ┆ 8 ┆ c │
|
342
372
|
# # └───────┴────────┴────────┘
|
343
373
|
def columns=(columns)
|
@@ -497,8 +527,12 @@ module Polars
|
|
497
527
|
columns.include?(name)
|
498
528
|
end
|
499
529
|
|
500
|
-
#
|
501
|
-
#
|
530
|
+
# Returns an enumerator.
|
531
|
+
#
|
532
|
+
# @return [Object]
|
533
|
+
def each(&block)
|
534
|
+
get_columns.each(&block)
|
535
|
+
end
|
502
536
|
|
503
537
|
# Returns subset of the DataFrame.
|
504
538
|
#
|
@@ -605,6 +639,7 @@ module Polars
|
|
605
639
|
# Set item.
|
606
640
|
#
|
607
641
|
# @return [Object]
|
642
|
+
#
|
608
643
|
# def []=(key, value)
|
609
644
|
# if key.is_a?(String)
|
610
645
|
# raise TypeError, "'DataFrame' object does not support 'Series' assignment by index. Use 'DataFrame.with_columns'"
|
@@ -613,6 +648,25 @@ module Polars
|
|
613
648
|
# raise Todo
|
614
649
|
# end
|
615
650
|
|
651
|
+
|
652
|
+
# Return the dataframe as a scalar.
|
653
|
+
#
|
654
|
+
# Equivalent to `df[0,0]`, with a check that the shape is (1,1).
|
655
|
+
#
|
656
|
+
# @return [Object]
|
657
|
+
#
|
658
|
+
# @example
|
659
|
+
# df = Polars::DataFrame.new({"a" => [1, 2, 3], "b" => [4, 5, 6]})
|
660
|
+
# result = df.select((Polars.col("a") * Polars.col("b")).sum)
|
661
|
+
# result.item
|
662
|
+
# # => 32
|
663
|
+
def item
|
664
|
+
if shape != [1, 1]
|
665
|
+
raise ArgumentError, "Can only call .item if the dataframe is of shape (1,1), dataframe is of shape #{shape}"
|
666
|
+
end
|
667
|
+
self[0, 0]
|
668
|
+
end
|
669
|
+
|
616
670
|
# no to_arrow
|
617
671
|
|
618
672
|
# Convert DataFrame to a hash mapping column name to values.
|
@@ -698,7 +752,7 @@ module Polars
|
|
698
752
|
pretty: false,
|
699
753
|
row_oriented: false
|
700
754
|
)
|
701
|
-
if
|
755
|
+
if Utils.pathlike?(file)
|
702
756
|
file = Utils.format_path(file)
|
703
757
|
end
|
704
758
|
|
@@ -713,7 +767,7 @@ module Polars
|
|
713
767
|
#
|
714
768
|
# @return [nil]
|
715
769
|
def write_ndjson(file)
|
716
|
-
if
|
770
|
+
if Utils.pathlike?(file)
|
717
771
|
file = Utils.format_path(file)
|
718
772
|
end
|
719
773
|
|
@@ -803,7 +857,7 @@ module Polars
|
|
803
857
|
return buffer.string.force_encoding(Encoding::UTF_8)
|
804
858
|
end
|
805
859
|
|
806
|
-
if
|
860
|
+
if Utils.pathlike?(file)
|
807
861
|
file = Utils.format_path(file)
|
808
862
|
end
|
809
863
|
|
@@ -841,7 +895,7 @@ module Polars
|
|
841
895
|
if compression.nil?
|
842
896
|
compression = "uncompressed"
|
843
897
|
end
|
844
|
-
if
|
898
|
+
if Utils.pathlike?(file)
|
845
899
|
file = Utils.format_path(file)
|
846
900
|
end
|
847
901
|
|
@@ -860,7 +914,7 @@ module Polars
|
|
860
914
|
if compression.nil?
|
861
915
|
compression = "uncompressed"
|
862
916
|
end
|
863
|
-
if
|
917
|
+
if Utils.pathlike?(file)
|
864
918
|
file = Utils.format_path(file)
|
865
919
|
end
|
866
920
|
|
@@ -902,7 +956,7 @@ module Polars
|
|
902
956
|
if compression.nil?
|
903
957
|
compression = "uncompressed"
|
904
958
|
end
|
905
|
-
if
|
959
|
+
if Utils.pathlike?(file)
|
906
960
|
file = Utils.format_path(file)
|
907
961
|
end
|
908
962
|
|
@@ -976,7 +1030,6 @@ module Polars
|
|
976
1030
|
# # │ str ┆ i64 ┆ i64 ┆ i64 │
|
977
1031
|
# # ╞════════╪══════════╪══════════╪══════════╡
|
978
1032
|
# # │ a ┆ 1 ┆ 2 ┆ 3 │
|
979
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
980
1033
|
# # │ b ┆ 1 ┆ 2 ┆ 3 │
|
981
1034
|
# # └────────┴──────────┴──────────┴──────────┘
|
982
1035
|
#
|
@@ -990,7 +1043,6 @@ module Polars
|
|
990
1043
|
# # │ i64 ┆ i64 ┆ i64 │
|
991
1044
|
# # ╞═════╪═════╪═════╡
|
992
1045
|
# # │ 1 ┆ 2 ┆ 3 │
|
993
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
994
1046
|
# # │ 1 ┆ 2 ┆ 3 │
|
995
1047
|
# # └─────┴─────┴─────┘
|
996
1048
|
#
|
@@ -1006,7 +1058,6 @@ module Polars
|
|
1006
1058
|
# # │ str ┆ i64 ┆ i64 ┆ i64 │
|
1007
1059
|
# # ╞═════╪═════╪═════╪═════╡
|
1008
1060
|
# # │ a ┆ 1 ┆ 2 ┆ 3 │
|
1009
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1010
1061
|
# # │ b ┆ 1 ┆ 2 ┆ 3 │
|
1011
1062
|
# # └─────┴─────┴─────┴─────┘
|
1012
1063
|
def transpose(include_header: false, header_name: "column", column_names: nil)
|
@@ -1048,9 +1099,7 @@ module Polars
|
|
1048
1099
|
# # │ str ┆ i64 │
|
1049
1100
|
# # ╞═════╪═════╡
|
1050
1101
|
# # │ c ┆ 3 │
|
1051
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1052
1102
|
# # │ b ┆ 2 │
|
1053
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1054
1103
|
# # │ a ┆ 1 │
|
1055
1104
|
# # └─────┴─────┘
|
1056
1105
|
def reverse
|
@@ -1081,9 +1130,7 @@ module Polars
|
|
1081
1130
|
# # │ i64 ┆ i64 ┆ str │
|
1082
1131
|
# # ╞═══════╪═════╪═════╡
|
1083
1132
|
# # │ 1 ┆ 6 ┆ a │
|
1084
|
-
# # ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1085
1133
|
# # │ 2 ┆ 7 ┆ b │
|
1086
|
-
# # ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1087
1134
|
# # │ 3 ┆ 8 ┆ c │
|
1088
1135
|
# # └───────┴─────┴─────┘
|
1089
1136
|
def rename(mapping)
|
@@ -1111,9 +1158,7 @@ module Polars
|
|
1111
1158
|
# # │ i64 ┆ i64 ┆ i64 │
|
1112
1159
|
# # ╞═════╪═════╪═════╡
|
1113
1160
|
# # │ 1 ┆ 97 ┆ 4 │
|
1114
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1115
1161
|
# # │ 2 ┆ 98 ┆ 5 │
|
1116
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1117
1162
|
# # │ 3 ┆ 99 ┆ 6 │
|
1118
1163
|
# # └─────┴─────┴─────┘
|
1119
1164
|
#
|
@@ -1135,11 +1180,8 @@ module Polars
|
|
1135
1180
|
# # │ i64 ┆ f64 ┆ bool ┆ f64 │
|
1136
1181
|
# # ╞═════╪══════╪═══════╪══════╡
|
1137
1182
|
# # │ 1 ┆ 0.5 ┆ true ┆ -2.5 │
|
1138
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
1139
1183
|
# # │ 2 ┆ 4.0 ┆ true ┆ 15.0 │
|
1140
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
1141
1184
|
# # │ 3 ┆ 10.0 ┆ false ┆ 20.5 │
|
1142
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
1143
1185
|
# # │ 4 ┆ 13.0 ┆ true ┆ 0.0 │
|
1144
1186
|
# # └─────┴──────┴───────┴──────┘
|
1145
1187
|
def insert_at_idx(index, series)
|
@@ -1174,7 +1216,6 @@ module Polars
|
|
1174
1216
|
# # │ i64 ┆ i64 ┆ str │
|
1175
1217
|
# # ╞═════╪═════╪═════╡
|
1176
1218
|
# # │ 1 ┆ 6 ┆ a │
|
1177
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1178
1219
|
# # │ 2 ┆ 7 ┆ b │
|
1179
1220
|
# # └─────┴─────┴─────┘
|
1180
1221
|
#
|
@@ -1216,17 +1257,11 @@ module Polars
|
|
1216
1257
|
# # │ str ┆ f64 ┆ f64 ┆ f64 ┆ str ┆ str │
|
1217
1258
|
# # ╞════════════╪══════════╪══════════╪══════════╪══════╪══════╡
|
1218
1259
|
# # │ count ┆ 3.0 ┆ 3.0 ┆ 3.0 ┆ 3 ┆ 3 │
|
1219
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
1220
1260
|
# # │ null_count ┆ 0.0 ┆ 1.0 ┆ 0.0 ┆ 1 ┆ 1 │
|
1221
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
1222
1261
|
# # │ mean ┆ 2.266667 ┆ 4.5 ┆ 0.666667 ┆ null ┆ null │
|
1223
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
1224
1262
|
# # │ std ┆ 1.101514 ┆ 0.707107 ┆ 0.57735 ┆ null ┆ null │
|
1225
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
1226
1263
|
# # │ min ┆ 1.0 ┆ 4.0 ┆ 0.0 ┆ b ┆ eur │
|
1227
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
1228
1264
|
# # │ max ┆ 3.0 ┆ 5.0 ┆ 1.0 ┆ c ┆ usd │
|
1229
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
1230
1265
|
# # │ median ┆ 2.8 ┆ 4.5 ┆ 1.0 ┆ null ┆ null │
|
1231
1266
|
# # └────────────┴──────────┴──────────┴──────────┴──────┴──────┘
|
1232
1267
|
def describe
|
@@ -1313,9 +1348,7 @@ module Polars
|
|
1313
1348
|
# # │ i64 ┆ i64 ┆ str │
|
1314
1349
|
# # ╞═══════╪═════╪═════╡
|
1315
1350
|
# # │ 10 ┆ 6 ┆ a │
|
1316
|
-
# # ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1317
1351
|
# # │ 20 ┆ 7 ┆ b │
|
1318
|
-
# # ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1319
1352
|
# # │ 30 ┆ 8 ┆ c │
|
1320
1353
|
# # └───────┴─────┴─────┘
|
1321
1354
|
def replace_at_idx(index, series)
|
@@ -1354,9 +1387,7 @@ module Polars
|
|
1354
1387
|
# # │ i64 ┆ f64 ┆ str │
|
1355
1388
|
# # ╞═════╪═════╪═════╡
|
1356
1389
|
# # │ 3 ┆ 8.0 ┆ c │
|
1357
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1358
1390
|
# # │ 2 ┆ 7.0 ┆ b │
|
1359
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1360
1391
|
# # │ 1 ┆ 6.0 ┆ a │
|
1361
1392
|
# # └─────┴─────┴─────┘
|
1362
1393
|
#
|
@@ -1373,9 +1404,7 @@ module Polars
|
|
1373
1404
|
# # │ i64 ┆ f64 ┆ str │
|
1374
1405
|
# # ╞═════╪═════╪═════╡
|
1375
1406
|
# # │ 3 ┆ 8.0 ┆ c │
|
1376
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1377
1407
|
# # │ 2 ┆ 7.0 ┆ b │
|
1378
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1379
1408
|
# # │ 1 ┆ 6.0 ┆ a │
|
1380
1409
|
# # └─────┴─────┴─────┘
|
1381
1410
|
def sort(by, reverse: false, nulls_last: false)
|
@@ -1441,9 +1470,7 @@ module Polars
|
|
1441
1470
|
# # │ i64 ┆ i64 │
|
1442
1471
|
# # ╞═════╪═════╡
|
1443
1472
|
# # │ 10 ┆ 4 │
|
1444
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1445
1473
|
# # │ 20 ┆ 5 │
|
1446
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1447
1474
|
# # │ 30 ┆ 6 │
|
1448
1475
|
# # └─────┴─────┘
|
1449
1476
|
def replace(column, new_col)
|
@@ -1478,7 +1505,6 @@ module Polars
|
|
1478
1505
|
# # │ i64 ┆ f64 ┆ str │
|
1479
1506
|
# # ╞═════╪═════╪═════╡
|
1480
1507
|
# # │ 2 ┆ 7.0 ┆ b │
|
1481
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1482
1508
|
# # │ 3 ┆ 8.0 ┆ c │
|
1483
1509
|
# # └─────┴─────┴─────┘
|
1484
1510
|
def slice(offset, length = nil)
|
@@ -1510,11 +1536,8 @@ module Polars
|
|
1510
1536
|
# # │ i64 ┆ str │
|
1511
1537
|
# # ╞═════╪═════╡
|
1512
1538
|
# # │ 1 ┆ a │
|
1513
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1514
1539
|
# # │ 2 ┆ b │
|
1515
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1516
1540
|
# # │ 3 ┆ c │
|
1517
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1518
1541
|
# # │ 4 ┆ d │
|
1519
1542
|
# # └─────┴─────┘
|
1520
1543
|
def limit(n = 5)
|
@@ -1545,9 +1568,7 @@ module Polars
|
|
1545
1568
|
# # │ i64 ┆ i64 ┆ str │
|
1546
1569
|
# # ╞═════╪═════╪═════╡
|
1547
1570
|
# # │ 1 ┆ 6 ┆ a │
|
1548
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1549
1571
|
# # │ 2 ┆ 7 ┆ b │
|
1550
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1551
1572
|
# # │ 3 ┆ 8 ┆ c │
|
1552
1573
|
# # └─────┴─────┴─────┘
|
1553
1574
|
def head(n = 5)
|
@@ -1578,9 +1599,7 @@ module Polars
|
|
1578
1599
|
# # │ i64 ┆ i64 ┆ str │
|
1579
1600
|
# # ╞═════╪═════╪═════╡
|
1580
1601
|
# # │ 3 ┆ 8 ┆ c │
|
1581
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1582
1602
|
# # │ 4 ┆ 9 ┆ d │
|
1583
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1584
1603
|
# # │ 5 ┆ 10 ┆ e │
|
1585
1604
|
# # └─────┴─────┴─────┘
|
1586
1605
|
def tail(n = 5)
|
@@ -1611,7 +1630,6 @@ module Polars
|
|
1611
1630
|
# # │ i64 ┆ i64 ┆ str │
|
1612
1631
|
# # ╞═════╪═════╪═════╡
|
1613
1632
|
# # │ 1 ┆ 6 ┆ a │
|
1614
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1615
1633
|
# # │ 3 ┆ 8 ┆ c │
|
1616
1634
|
# # └─────┴─────┴─────┘
|
1617
1635
|
def drop_nulls(subset: nil)
|
@@ -1653,11 +1671,8 @@ module Polars
|
|
1653
1671
|
# # │ i64 ┆ i64 │
|
1654
1672
|
# # ╞═════╪═════╡
|
1655
1673
|
# # │ 1 ┆ 10 │
|
1656
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1657
1674
|
# # │ 2 ┆ 20 │
|
1658
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1659
1675
|
# # │ 3 ┆ 30 │
|
1660
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1661
1676
|
# # │ 4 ┆ 40 │
|
1662
1677
|
# # └─────┴─────┘
|
1663
1678
|
def pipe(func, *args, **kwargs, &block)
|
@@ -1689,9 +1704,7 @@ module Polars
|
|
1689
1704
|
# # │ u32 ┆ i64 ┆ i64 │
|
1690
1705
|
# # ╞════════╪═════╪═════╡
|
1691
1706
|
# # │ 0 ┆ 1 ┆ 2 │
|
1692
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1693
1707
|
# # │ 1 ┆ 3 ┆ 4 │
|
1694
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
1695
1708
|
# # │ 2 ┆ 5 ┆ 6 │
|
1696
1709
|
# # └────────┴─────┴─────┘
|
1697
1710
|
def with_row_count(name: "row_nr", offset: 0)
|
@@ -1726,18 +1739,13 @@ module Polars
|
|
1726
1739
|
# # │ str ┆ i64 │
|
1727
1740
|
# # ╞═════╪═════╡
|
1728
1741
|
# # │ a ┆ 4 │
|
1729
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1730
1742
|
# # │ b ┆ 11 │
|
1731
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
1732
1743
|
# # │ c ┆ 6 │
|
1733
1744
|
# # └─────┴─────┘
|
1734
1745
|
def groupby(by, maintain_order: false)
|
1735
1746
|
if !Utils.bool?(maintain_order)
|
1736
1747
|
raise TypeError, "invalid input for groupby arg `maintain_order`: #{maintain_order}."
|
1737
1748
|
end
|
1738
|
-
if by.is_a?(String)
|
1739
|
-
by = [by]
|
1740
|
-
end
|
1741
1749
|
GroupBy.new(
|
1742
1750
|
_df,
|
1743
1751
|
by,
|
@@ -1824,15 +1832,10 @@ module Polars
|
|
1824
1832
|
# # │ datetime[μs] ┆ i64 ┆ i64 ┆ i64 │
|
1825
1833
|
# # ╞═════════════════════╪═══════╪═══════╪═══════╡
|
1826
1834
|
# # │ 2020-01-01 13:45:48 ┆ 3 ┆ 3 ┆ 3 │
|
1827
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
1828
1835
|
# # │ 2020-01-01 16:42:13 ┆ 10 ┆ 3 ┆ 7 │
|
1829
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
1830
1836
|
# # │ 2020-01-01 16:45:09 ┆ 15 ┆ 3 ┆ 7 │
|
1831
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
1832
1837
|
# # │ 2020-01-02 18:12:48 ┆ 24 ┆ 3 ┆ 9 │
|
1833
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
1834
1838
|
# # │ 2020-01-03 19:45:32 ┆ 11 ┆ 2 ┆ 9 │
|
1835
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
1836
1839
|
# # │ 2020-01-08 23:16:43 ┆ 1 ┆ 1 ┆ 1 │
|
1837
1840
|
# # └─────────────────────┴───────┴───────┴───────┘
|
1838
1841
|
def groupby_rolling(
|
@@ -1929,17 +1932,11 @@ module Polars
|
|
1929
1932
|
# # │ datetime[μs] ┆ i64 │
|
1930
1933
|
# # ╞═════════════════════╪═════╡
|
1931
1934
|
# # │ 2021-12-16 00:00:00 ┆ 0 │
|
1932
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
1933
1935
|
# # │ 2021-12-16 00:30:00 ┆ 1 │
|
1934
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
1935
1936
|
# # │ 2021-12-16 01:00:00 ┆ 2 │
|
1936
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
1937
1937
|
# # │ 2021-12-16 01:30:00 ┆ 3 │
|
1938
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
1939
1938
|
# # │ 2021-12-16 02:00:00 ┆ 4 │
|
1940
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
1941
1939
|
# # │ 2021-12-16 02:30:00 ┆ 5 │
|
1942
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
1943
1940
|
# # │ 2021-12-16 03:00:00 ┆ 6 │
|
1944
1941
|
# # └─────────────────────┴─────┘
|
1945
1942
|
#
|
@@ -1958,11 +1955,8 @@ module Polars
|
|
1958
1955
|
# # │ datetime[μs] ┆ datetime[μs] ┆ datetime[μs] │
|
1959
1956
|
# # ╞═════════════════════╪═════════════════════╪═════════════════════╡
|
1960
1957
|
# # │ 2021-12-15 23:00:00 ┆ 2021-12-16 00:00:00 ┆ 2021-12-16 00:00:00 │
|
1961
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
1962
1958
|
# # │ 2021-12-16 00:00:00 ┆ 2021-12-16 00:30:00 ┆ 2021-12-16 01:00:00 │
|
1963
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
1964
1959
|
# # │ 2021-12-16 01:00:00 ┆ 2021-12-16 01:30:00 ┆ 2021-12-16 02:00:00 │
|
1965
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
1966
1960
|
# # │ 2021-12-16 02:00:00 ┆ 2021-12-16 02:30:00 ┆ 2021-12-16 03:00:00 │
|
1967
1961
|
# # └─────────────────────┴─────────────────────┴─────────────────────┘
|
1968
1962
|
#
|
@@ -1978,11 +1972,8 @@ module Polars
|
|
1978
1972
|
# # │ datetime[μs] ┆ datetime[μs] ┆ datetime[μs] ┆ u32 │
|
1979
1973
|
# # ╞═════════════════════╪═════════════════════╪═════════════════════╪════════════╡
|
1980
1974
|
# # │ 2021-12-15 23:00:00 ┆ 2021-12-16 00:00:00 ┆ 2021-12-15 23:00:00 ┆ 1 │
|
1981
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
1982
1975
|
# # │ 2021-12-16 00:00:00 ┆ 2021-12-16 01:00:00 ┆ 2021-12-16 00:00:00 ┆ 2 │
|
1983
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
1984
1976
|
# # │ 2021-12-16 01:00:00 ┆ 2021-12-16 02:00:00 ┆ 2021-12-16 01:00:00 ┆ 2 │
|
1985
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
1986
1977
|
# # │ 2021-12-16 02:00:00 ┆ 2021-12-16 03:00:00 ┆ 2021-12-16 02:00:00 ┆ 2 │
|
1987
1978
|
# # └─────────────────────┴─────────────────────┴─────────────────────┴────────────┘
|
1988
1979
|
#
|
@@ -2001,11 +1992,8 @@ module Polars
|
|
2001
1992
|
# # │ datetime[μs] ┆ u32 ┆ list[datetime[μs]] │
|
2002
1993
|
# # ╞═════════════════════╪════════════╪═════════════════════════════════════╡
|
2003
1994
|
# # │ 2021-12-16 00:00:00 ┆ 2 ┆ [2021-12-16 00:00:00, 2021-12-16... │
|
2004
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2005
1995
|
# # │ 2021-12-16 01:00:00 ┆ 2 ┆ [2021-12-16 01:00:00, 2021-12-16... │
|
2006
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2007
1996
|
# # │ 2021-12-16 02:00:00 ┆ 2 ┆ [2021-12-16 02:00:00, 2021-12-16... │
|
2008
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2009
1997
|
# # │ 2021-12-16 03:00:00 ┆ 1 ┆ [2021-12-16 03:00:00] │
|
2010
1998
|
# # └─────────────────────┴────────────┴─────────────────────────────────────┘
|
2011
1999
|
#
|
@@ -2021,13 +2009,9 @@ module Polars
|
|
2021
2009
|
# # │ datetime[μs] ┆ u32 │
|
2022
2010
|
# # ╞═════════════════════╪════════════╡
|
2023
2011
|
# # │ 2021-12-15 23:00:00 ┆ 1 │
|
2024
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2025
2012
|
# # │ 2021-12-16 00:00:00 ┆ 3 │
|
2026
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2027
2013
|
# # │ 2021-12-16 01:00:00 ┆ 3 │
|
2028
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2029
2014
|
# # │ 2021-12-16 02:00:00 ┆ 3 │
|
2030
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2031
2015
|
# # │ 2021-12-16 03:00:00 ┆ 1 │
|
2032
2016
|
# # └─────────────────────┴────────────┘
|
2033
2017
|
#
|
@@ -2057,17 +2041,11 @@ module Polars
|
|
2057
2041
|
# # │ str ┆ datetime[μs] ┆ datetime[μs] ┆ datetime[μs] ┆ u32 │
|
2058
2042
|
# # ╞════════╪═════════════════════╪═════════════════════╪═════════════════════╪════════════╡
|
2059
2043
|
# # │ a ┆ 2021-12-15 23:00:00 ┆ 2021-12-16 00:00:00 ┆ 2021-12-15 23:00:00 ┆ 1 │
|
2060
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2061
2044
|
# # │ a ┆ 2021-12-16 00:00:00 ┆ 2021-12-16 01:00:00 ┆ 2021-12-16 00:00:00 ┆ 3 │
|
2062
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2063
2045
|
# # │ a ┆ 2021-12-16 01:00:00 ┆ 2021-12-16 02:00:00 ┆ 2021-12-16 01:00:00 ┆ 1 │
|
2064
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2065
2046
|
# # │ a ┆ 2021-12-16 02:00:00 ┆ 2021-12-16 03:00:00 ┆ 2021-12-16 02:00:00 ┆ 2 │
|
2066
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2067
2047
|
# # │ a ┆ 2021-12-16 03:00:00 ┆ 2021-12-16 04:00:00 ┆ 2021-12-16 03:00:00 ┆ 1 │
|
2068
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2069
2048
|
# # │ b ┆ 2021-12-16 01:00:00 ┆ 2021-12-16 02:00:00 ┆ 2021-12-16 01:00:00 ┆ 2 │
|
2070
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2071
2049
|
# # │ b ┆ 2021-12-16 02:00:00 ┆ 2021-12-16 03:00:00 ┆ 2021-12-16 02:00:00 ┆ 1 │
|
2072
2050
|
# # └────────┴─────────────────────┴─────────────────────┴─────────────────────┴────────────┘
|
2073
2051
|
#
|
@@ -2093,9 +2071,7 @@ module Polars
|
|
2093
2071
|
# # │ i64 ┆ i64 ┆ i64 ┆ list[str] │
|
2094
2072
|
# # ╞═════════════════╪═════════════════╪═════╪═════════════════╡
|
2095
2073
|
# # │ 0 ┆ 3 ┆ 0 ┆ ["A", "B", "B"] │
|
2096
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2097
2074
|
# # │ 2 ┆ 5 ┆ 2 ┆ ["B", "B", "C"] │
|
2098
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
2099
2075
|
# # │ 4 ┆ 7 ┆ 4 ┆ ["C"] │
|
2100
2076
|
# # └─────────────────┴─────────────────┴─────┴─────────────────┘
|
2101
2077
|
def groupby_dynamic(
|
@@ -2181,17 +2157,11 @@ module Polars
|
|
2181
2157
|
# # │ datetime[ns] ┆ str ┆ i64 │
|
2182
2158
|
# # ╞═════════════════════╪════════╪════════╡
|
2183
2159
|
# # │ 2021-02-01 00:00:00 ┆ A ┆ 0 │
|
2184
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
2185
2160
|
# # │ 2021-03-01 00:00:00 ┆ A ┆ 0 │
|
2186
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
2187
2161
|
# # │ 2021-04-01 00:00:00 ┆ A ┆ 0 │
|
2188
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
2189
2162
|
# # │ 2021-05-01 00:00:00 ┆ A ┆ 2 │
|
2190
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
2191
2163
|
# # │ 2021-04-01 00:00:00 ┆ B ┆ 1 │
|
2192
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
2193
2164
|
# # │ 2021-05-01 00:00:00 ┆ B ┆ 1 │
|
2194
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
2195
2165
|
# # │ 2021-06-01 00:00:00 ┆ B ┆ 3 │
|
2196
2166
|
# # └─────────────────────┴────────┴────────┘
|
2197
2167
|
def upsample(
|
@@ -2316,11 +2286,8 @@ module Polars
|
|
2316
2286
|
# # │ datetime[ns] ┆ f64 ┆ i64 │
|
2317
2287
|
# # ╞═════════════════════╪════════════╪══════╡
|
2318
2288
|
# # │ 2016-05-12 00:00:00 ┆ 82.19 ┆ 4164 │
|
2319
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2320
2289
|
# # │ 2017-05-12 00:00:00 ┆ 82.66 ┆ 4411 │
|
2321
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2322
2290
|
# # │ 2018-05-12 00:00:00 ┆ 83.12 ┆ 4566 │
|
2323
|
-
# # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2324
2291
|
# # │ 2019-05-12 00:00:00 ┆ 83.52 ┆ 4696 │
|
2325
2292
|
# # └─────────────────────┴────────────┴──────┘
|
2326
2293
|
def join_asof(
|
@@ -2395,7 +2362,6 @@ module Polars
|
|
2395
2362
|
# # │ i64 ┆ f64 ┆ str ┆ str │
|
2396
2363
|
# # ╞═════╪═════╪═════╪═══════╡
|
2397
2364
|
# # │ 1 ┆ 6.0 ┆ a ┆ x │
|
2398
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
2399
2365
|
# # │ 2 ┆ 7.0 ┆ b ┆ y │
|
2400
2366
|
# # └─────┴─────┴─────┴───────┘
|
2401
2367
|
#
|
@@ -2409,11 +2375,8 @@ module Polars
|
|
2409
2375
|
# # │ i64 ┆ f64 ┆ str ┆ str │
|
2410
2376
|
# # ╞══════╪══════╪═════╪═══════╡
|
2411
2377
|
# # │ 1 ┆ 6.0 ┆ a ┆ x │
|
2412
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
2413
2378
|
# # │ 2 ┆ 7.0 ┆ b ┆ y │
|
2414
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
2415
2379
|
# # │ null ┆ null ┆ d ┆ z │
|
2416
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
2417
2380
|
# # │ 3 ┆ 8.0 ┆ c ┆ null │
|
2418
2381
|
# # └──────┴──────┴─────┴───────┘
|
2419
2382
|
#
|
@@ -2427,9 +2390,7 @@ module Polars
|
|
2427
2390
|
# # │ i64 ┆ f64 ┆ str ┆ str │
|
2428
2391
|
# # ╞═════╪═════╪═════╪═══════╡
|
2429
2392
|
# # │ 1 ┆ 6.0 ┆ a ┆ x │
|
2430
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
2431
2393
|
# # │ 2 ┆ 7.0 ┆ b ┆ y │
|
2432
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
2433
2394
|
# # │ 3 ┆ 8.0 ┆ c ┆ null │
|
2434
2395
|
# # └─────┴─────┴─────┴───────┘
|
2435
2396
|
#
|
@@ -2443,7 +2404,6 @@ module Polars
|
|
2443
2404
|
# # │ i64 ┆ f64 ┆ str │
|
2444
2405
|
# # ╞═════╪═════╪═════╡
|
2445
2406
|
# # │ 1 ┆ 6.0 ┆ a │
|
2446
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
2447
2407
|
# # │ 2 ┆ 7.0 ┆ b │
|
2448
2408
|
# # └─────┴─────┴─────┘
|
2449
2409
|
#
|
@@ -2514,9 +2474,7 @@ module Polars
|
|
2514
2474
|
# # │ i64 ┆ i64 │
|
2515
2475
|
# # ╞══════════╪══════════╡
|
2516
2476
|
# # │ 2 ┆ -3 │
|
2517
|
-
# # ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
2518
2477
|
# # │ 4 ┆ 15 │
|
2519
|
-
# # ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
2520
2478
|
# # │ 6 ┆ 24 │
|
2521
2479
|
# # └──────────┴──────────┘
|
2522
2480
|
#
|
@@ -2530,9 +2488,7 @@ module Polars
|
|
2530
2488
|
# # │ i64 │
|
2531
2489
|
# # ╞═══════╡
|
2532
2490
|
# # │ 1 │
|
2533
|
-
# # ├╌╌╌╌╌╌╌┤
|
2534
2491
|
# # │ 9 │
|
2535
|
-
# # ├╌╌╌╌╌╌╌┤
|
2536
2492
|
# # │ 14 │
|
2537
2493
|
# # └───────┘
|
2538
2494
|
def apply(return_dtype: nil, inference_size: 256, &f)
|
@@ -2567,9 +2523,7 @@ module Polars
|
|
2567
2523
|
# # │ i64 ┆ i64 ┆ f64 │
|
2568
2524
|
# # ╞═════╪═════╪═══════════╡
|
2569
2525
|
# # │ 1 ┆ 2 ┆ 4.0 │
|
2570
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
|
2571
2526
|
# # │ 3 ┆ 4 ┆ 16.0 │
|
2572
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
|
2573
2527
|
# # │ 5 ┆ 6 ┆ 36.0 │
|
2574
2528
|
# # └─────┴─────┴───────────┘
|
2575
2529
|
#
|
@@ -2583,9 +2537,7 @@ module Polars
|
|
2583
2537
|
# # │ f64 ┆ i64 │
|
2584
2538
|
# # ╞══════╪═════╡
|
2585
2539
|
# # │ 1.0 ┆ 2 │
|
2586
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌┤
|
2587
2540
|
# # │ 9.0 ┆ 4 │
|
2588
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌┤
|
2589
2541
|
# # │ 25.0 ┆ 6 │
|
2590
2542
|
# # └──────┴─────┘
|
2591
2543
|
def with_column(column)
|
@@ -2621,9 +2573,7 @@ module Polars
|
|
2621
2573
|
# # │ i64 ┆ i64 ┆ str ┆ i64 │
|
2622
2574
|
# # ╞═════╪═════╪═════╪═══════╡
|
2623
2575
|
# # │ 1 ┆ 6 ┆ a ┆ 10 │
|
2624
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
2625
2576
|
# # │ 2 ┆ 7 ┆ b ┆ 20 │
|
2626
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
2627
2577
|
# # │ 3 ┆ 8 ┆ c ┆ 30 │
|
2628
2578
|
# # └─────┴─────┴─────┴───────┘
|
2629
2579
|
def hstack(columns, in_place: false)
|
@@ -2671,11 +2621,8 @@ module Polars
|
|
2671
2621
|
# # │ i64 ┆ i64 ┆ str │
|
2672
2622
|
# # ╞═════╪═════╪═════╡
|
2673
2623
|
# # │ 1 ┆ 6 ┆ a │
|
2674
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
2675
2624
|
# # │ 2 ┆ 7 ┆ b │
|
2676
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
2677
2625
|
# # │ 3 ┆ 8 ┆ c │
|
2678
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
2679
2626
|
# # │ 4 ┆ 9 ┆ d │
|
2680
2627
|
# # └─────┴─────┴─────┘
|
2681
2628
|
def vstack(df, in_place: false)
|
@@ -2721,15 +2668,10 @@ module Polars
|
|
2721
2668
|
# # │ i64 ┆ i64 │
|
2722
2669
|
# # ╞═════╪═════╡
|
2723
2670
|
# # │ 1 ┆ 4 │
|
2724
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
2725
2671
|
# # │ 2 ┆ 5 │
|
2726
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
2727
2672
|
# # │ 3 ┆ 6 │
|
2728
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
2729
2673
|
# # │ 10 ┆ 40 │
|
2730
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
2731
2674
|
# # │ 20 ┆ 50 │
|
2732
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
2733
2675
|
# # │ 30 ┆ 60 │
|
2734
2676
|
# # └─────┴─────┘
|
2735
2677
|
def extend(other)
|
@@ -2761,9 +2703,7 @@ module Polars
|
|
2761
2703
|
# # │ i64 ┆ f64 │
|
2762
2704
|
# # ╞═════╪═════╡
|
2763
2705
|
# # │ 1 ┆ 6.0 │
|
2764
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
2765
2706
|
# # │ 2 ┆ 7.0 │
|
2766
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
2767
2707
|
# # │ 3 ┆ 8.0 │
|
2768
2708
|
# # └─────┴─────┘
|
2769
2709
|
def drop(columns)
|
@@ -2894,11 +2834,8 @@ module Polars
|
|
2894
2834
|
# # │ i64 ┆ f64 │
|
2895
2835
|
# # ╞═════╪══════╡
|
2896
2836
|
# # │ 1 ┆ 0.5 │
|
2897
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2898
2837
|
# # │ 2 ┆ 4.0 │
|
2899
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2900
2838
|
# # │ 99 ┆ 99.0 │
|
2901
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2902
2839
|
# # │ 4 ┆ 13.0 │
|
2903
2840
|
# # └─────┴──────┘
|
2904
2841
|
#
|
@@ -2912,11 +2849,8 @@ module Polars
|
|
2912
2849
|
# # │ i64 ┆ f64 │
|
2913
2850
|
# # ╞═════╪══════╡
|
2914
2851
|
# # │ 1 ┆ 0.5 │
|
2915
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2916
2852
|
# # │ 2 ┆ 4.0 │
|
2917
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2918
2853
|
# # │ 2 ┆ 4.0 │
|
2919
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2920
2854
|
# # │ 4 ┆ 13.0 │
|
2921
2855
|
# # └─────┴──────┘
|
2922
2856
|
#
|
@@ -2930,11 +2864,8 @@ module Polars
|
|
2930
2864
|
# # │ i64 ┆ f64 │
|
2931
2865
|
# # ╞═════╪══════╡
|
2932
2866
|
# # │ 1 ┆ 0.5 │
|
2933
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2934
2867
|
# # │ 2 ┆ 4.0 │
|
2935
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2936
2868
|
# # │ 4 ┆ 13.0 │
|
2937
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2938
2869
|
# # │ 4 ┆ 13.0 │
|
2939
2870
|
# # └─────┴──────┘
|
2940
2871
|
#
|
@@ -2948,11 +2879,8 @@ module Polars
|
|
2948
2879
|
# # │ i64 ┆ f64 │
|
2949
2880
|
# # ╞═════╪══════╡
|
2950
2881
|
# # │ 1 ┆ 0.5 │
|
2951
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2952
2882
|
# # │ 2 ┆ 4.0 │
|
2953
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2954
2883
|
# # │ 0 ┆ 0.0 │
|
2955
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2956
2884
|
# # │ 4 ┆ 13.0 │
|
2957
2885
|
# # └─────┴──────┘
|
2958
2886
|
def fill_null(value = nil, strategy: nil, limit: nil, matches_supertype: true)
|
@@ -2991,11 +2919,8 @@ module Polars
|
|
2991
2919
|
# # │ f64 ┆ f64 │
|
2992
2920
|
# # ╞══════╪══════╡
|
2993
2921
|
# # │ 1.5 ┆ 0.5 │
|
2994
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2995
2922
|
# # │ 2.0 ┆ 4.0 │
|
2996
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2997
2923
|
# # │ 99.0 ┆ 99.0 │
|
2998
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
2999
2924
|
# # │ 4.0 ┆ 13.0 │
|
3000
2925
|
# # └──────┴──────┘
|
3001
2926
|
def fill_nan(fill_value)
|
@@ -3025,19 +2950,12 @@ module Polars
|
|
3025
2950
|
# # │ str ┆ i64 │
|
3026
2951
|
# # ╞═════════╪═════════╡
|
3027
2952
|
# # │ a ┆ 1 │
|
3028
|
-
# # ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
3029
2953
|
# # │ a ┆ 2 │
|
3030
|
-
# # ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
3031
2954
|
# # │ a ┆ 3 │
|
3032
|
-
# # ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
3033
2955
|
# # │ b ┆ 4 │
|
3034
|
-
# # ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
3035
2956
|
# # │ b ┆ 5 │
|
3036
|
-
# # ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
3037
2957
|
# # │ c ┆ 6 │
|
3038
|
-
# # ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
3039
2958
|
# # │ c ┆ 7 │
|
3040
|
-
# # ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
|
3041
2959
|
# # │ c ┆ 8 │
|
3042
2960
|
# # └─────────┴─────────┘
|
3043
2961
|
def explode(columns)
|
@@ -3079,7 +2997,6 @@ module Polars
|
|
3079
2997
|
# # │ str ┆ i64 ┆ i64 ┆ i64 │
|
3080
2998
|
# # ╞═════╪═════╪═════╪═════╡
|
3081
2999
|
# # │ one ┆ 1 ┆ 2 ┆ 3 │
|
3082
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
3083
3000
|
# # │ two ┆ 4 ┆ 5 ┆ 6 │
|
3084
3001
|
# # └─────┴─────┴─────┴─────┘
|
3085
3002
|
def pivot(
|
@@ -3088,7 +3005,8 @@ module Polars
|
|
3088
3005
|
columns:,
|
3089
3006
|
aggregate_fn: "first",
|
3090
3007
|
maintain_order: true,
|
3091
|
-
sort_columns: false
|
3008
|
+
sort_columns: false,
|
3009
|
+
separator: "_"
|
3092
3010
|
)
|
3093
3011
|
if values.is_a?(String)
|
3094
3012
|
values = [values]
|
@@ -3130,7 +3048,8 @@ module Polars
|
|
3130
3048
|
columns,
|
3131
3049
|
aggregate_fn._rbexpr,
|
3132
3050
|
maintain_order,
|
3133
|
-
sort_columns
|
3051
|
+
sort_columns,
|
3052
|
+
separator
|
3134
3053
|
)
|
3135
3054
|
)
|
3136
3055
|
end
|
@@ -3173,15 +3092,10 @@ module Polars
|
|
3173
3092
|
# # │ str ┆ str ┆ i64 │
|
3174
3093
|
# # ╞═════╪══════════╪═══════╡
|
3175
3094
|
# # │ x ┆ b ┆ 1 │
|
3176
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
3177
3095
|
# # │ y ┆ b ┆ 3 │
|
3178
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
3179
3096
|
# # │ z ┆ b ┆ 5 │
|
3180
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
3181
3097
|
# # │ x ┆ c ┆ 2 │
|
3182
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
3183
3098
|
# # │ y ┆ c ┆ 4 │
|
3184
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
3185
3099
|
# # │ z ┆ c ┆ 6 │
|
3186
3100
|
# # └─────┴──────────┴───────┘
|
3187
3101
|
def melt(id_vars: nil, value_vars: nil, variable_name: nil, value_name: nil)
|
@@ -3236,21 +3150,13 @@ module Polars
|
|
3236
3150
|
# # │ str ┆ i64 │
|
3237
3151
|
# # ╞══════╪══════╡
|
3238
3152
|
# # │ A ┆ 0 │
|
3239
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3240
3153
|
# # │ B ┆ 1 │
|
3241
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3242
3154
|
# # │ C ┆ 2 │
|
3243
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3244
3155
|
# # │ D ┆ 3 │
|
3245
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3246
3156
|
# # │ ... ┆ ... │
|
3247
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3248
3157
|
# # │ F ┆ 5 │
|
3249
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3250
3158
|
# # │ G ┆ 6 │
|
3251
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3252
3159
|
# # │ H ┆ 7 │
|
3253
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3254
3160
|
# # │ I ┆ 8 │
|
3255
3161
|
# # └──────┴──────┘
|
3256
3162
|
#
|
@@ -3264,9 +3170,7 @@ module Polars
|
|
3264
3170
|
# # │ str ┆ str ┆ str ┆ i64 ┆ i64 ┆ i64 │
|
3265
3171
|
# # ╞════════╪════════╪════════╪════════╪════════╪════════╡
|
3266
3172
|
# # │ A ┆ D ┆ G ┆ 0 ┆ 3 ┆ 6 │
|
3267
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
3268
3173
|
# # │ B ┆ E ┆ H ┆ 1 ┆ 4 ┆ 7 │
|
3269
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
3270
3174
|
# # │ C ┆ F ┆ I ┆ 2 ┆ 5 ┆ 8 │
|
3271
3175
|
# # └────────┴────────┴────────┴────────┴────────┴────────┘
|
3272
3176
|
#
|
@@ -3280,9 +3184,7 @@ module Polars
|
|
3280
3184
|
# # │ str ┆ str ┆ str ┆ i64 ┆ i64 ┆ i64 │
|
3281
3185
|
# # ╞════════╪════════╪════════╪════════╪════════╪════════╡
|
3282
3186
|
# # │ A ┆ B ┆ C ┆ 0 ┆ 1 ┆ 2 │
|
3283
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
3284
3187
|
# # │ D ┆ E ┆ F ┆ 3 ┆ 4 ┆ 5 │
|
3285
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
3286
3188
|
# # │ G ┆ H ┆ I ┆ 6 ┆ 7 ┆ 8 │
|
3287
3189
|
# # └────────┴────────┴────────┴────────┴────────┴────────┘
|
3288
3190
|
def unstack(step:, how: "vertical", columns: nil, fill_values: nil)
|
@@ -3368,7 +3270,6 @@ module Polars
|
|
3368
3270
|
# # │ str ┆ i64 ┆ str │
|
3369
3271
|
# # ╞═════╪═════╪═════╡
|
3370
3272
|
# # │ A ┆ 1 ┆ k │
|
3371
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
3372
3273
|
# # │ A ┆ 2 ┆ l │
|
3373
3274
|
# # └─────┴─────┴─────┘, shape: (2, 3)
|
3374
3275
|
# # ┌─────┬─────┬─────┐
|
@@ -3377,7 +3278,6 @@ module Polars
|
|
3377
3278
|
# # │ str ┆ i64 ┆ str │
|
3378
3279
|
# # ╞═════╪═════╪═════╡
|
3379
3280
|
# # │ B ┆ 2 ┆ m │
|
3380
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
3381
3281
|
# # │ B ┆ 4 ┆ m │
|
3382
3282
|
# # └─────┴─────┴─────┘, shape: (1, 3)
|
3383
3283
|
# # ┌─────┬─────┬─────┐
|
@@ -3398,7 +3298,6 @@ module Polars
|
|
3398
3298
|
# # │ str ┆ i64 ┆ str │
|
3399
3299
|
# # ╞═════╪═════╪═════╡
|
3400
3300
|
# # │ A ┆ 1 ┆ k │
|
3401
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
3402
3301
|
# # │ A ┆ 2 ┆ l │
|
3403
3302
|
# # └─────┴─────┴─────┘, "B"=>shape: (2, 3)
|
3404
3303
|
# # ┌─────┬─────┬─────┐
|
@@ -3407,7 +3306,6 @@ module Polars
|
|
3407
3306
|
# # │ str ┆ i64 ┆ str │
|
3408
3307
|
# # ╞═════╪═════╪═════╡
|
3409
3308
|
# # │ B ┆ 2 ┆ m │
|
3410
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
3411
3309
|
# # │ B ┆ 4 ┆ m │
|
3412
3310
|
# # └─────┴─────┴─────┘, "C"=>shape: (1, 3)
|
3413
3311
|
# # ┌─────┬─────┬─────┐
|
@@ -3467,9 +3365,7 @@ module Polars
|
|
3467
3365
|
# # │ i64 ┆ i64 ┆ str │
|
3468
3366
|
# # ╞══════╪══════╪══════╡
|
3469
3367
|
# # │ null ┆ null ┆ null │
|
3470
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3471
3368
|
# # │ 1 ┆ 6 ┆ a │
|
3472
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3473
3369
|
# # │ 2 ┆ 7 ┆ b │
|
3474
3370
|
# # └──────┴──────┴──────┘
|
3475
3371
|
#
|
@@ -3483,9 +3379,7 @@ module Polars
|
|
3483
3379
|
# # │ i64 ┆ i64 ┆ str │
|
3484
3380
|
# # ╞══════╪══════╪══════╡
|
3485
3381
|
# # │ 2 ┆ 7 ┆ b │
|
3486
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3487
3382
|
# # │ 3 ┆ 8 ┆ c │
|
3488
|
-
# # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
3489
3383
|
# # │ null ┆ null ┆ null │
|
3490
3384
|
# # └──────┴──────┴──────┘
|
3491
3385
|
def shift(periods)
|
@@ -3518,9 +3412,7 @@ module Polars
|
|
3518
3412
|
# # │ i64 ┆ i64 ┆ str │
|
3519
3413
|
# # ╞═════╪═════╪═════╡
|
3520
3414
|
# # │ 0 ┆ 0 ┆ 0 │
|
3521
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
3522
3415
|
# # │ 1 ┆ 6 ┆ a │
|
3523
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
3524
3416
|
# # │ 2 ┆ 7 ┆ b │
|
3525
3417
|
# # └─────┴─────┴─────┘
|
3526
3418
|
def shift_and_fill(periods, fill_value)
|
@@ -3610,9 +3502,7 @@ module Polars
|
|
3610
3502
|
# # │ i64 │
|
3611
3503
|
# # ╞═════╡
|
3612
3504
|
# # │ 1 │
|
3613
|
-
# # ├╌╌╌╌╌┤
|
3614
3505
|
# # │ 2 │
|
3615
|
-
# # ├╌╌╌╌╌┤
|
3616
3506
|
# # │ 3 │
|
3617
3507
|
# # └─────┘
|
3618
3508
|
#
|
@@ -3626,9 +3516,7 @@ module Polars
|
|
3626
3516
|
# # │ i64 ┆ i64 │
|
3627
3517
|
# # ╞═════╪═════╡
|
3628
3518
|
# # │ 1 ┆ 6 │
|
3629
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
3630
3519
|
# # │ 2 ┆ 7 │
|
3631
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
3632
3520
|
# # │ 3 ┆ 8 │
|
3633
3521
|
# # └─────┴─────┘
|
3634
3522
|
#
|
@@ -3642,9 +3530,7 @@ module Polars
|
|
3642
3530
|
# # │ i64 │
|
3643
3531
|
# # ╞═════╡
|
3644
3532
|
# # │ 2 │
|
3645
|
-
# # ├╌╌╌╌╌┤
|
3646
3533
|
# # │ 3 │
|
3647
|
-
# # ├╌╌╌╌╌┤
|
3648
3534
|
# # │ 4 │
|
3649
3535
|
# # └─────┘
|
3650
3536
|
#
|
@@ -3658,9 +3544,7 @@ module Polars
|
|
3658
3544
|
# # │ i64 ┆ i64 │
|
3659
3545
|
# # ╞═════╪═════╡
|
3660
3546
|
# # │ 2 ┆ 7 │
|
3661
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
3662
3547
|
# # │ 3 ┆ 8 │
|
3663
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
3664
3548
|
# # │ 4 ┆ 9 │
|
3665
3549
|
# # └─────┴─────┘
|
3666
3550
|
#
|
@@ -3674,9 +3558,7 @@ module Polars
|
|
3674
3558
|
# # │ i64 │
|
3675
3559
|
# # ╞═════════╡
|
3676
3560
|
# # │ 0 │
|
3677
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
3678
3561
|
# # │ 0 │
|
3679
|
-
# # ├╌╌╌╌╌╌╌╌╌┤
|
3680
3562
|
# # │ 10 │
|
3681
3563
|
# # └─────────┘
|
3682
3564
|
def select(exprs)
|
@@ -3718,11 +3600,8 @@ module Polars
|
|
3718
3600
|
# # │ i64 ┆ f64 ┆ bool ┆ f64 ┆ f64 ┆ bool │
|
3719
3601
|
# # ╞═════╪══════╪═══════╪══════╪══════╪═══════╡
|
3720
3602
|
# # │ 1 ┆ 0.5 ┆ true ┆ 1.0 ┆ 0.25 ┆ false │
|
3721
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
3722
3603
|
# # │ 2 ┆ 4.0 ┆ true ┆ 4.0 ┆ 2.0 ┆ false │
|
3723
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
3724
3604
|
# # │ 3 ┆ 10.0 ┆ false ┆ 9.0 ┆ 5.0 ┆ true │
|
3725
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
3726
3605
|
# # │ 4 ┆ 13.0 ┆ true ┆ 16.0 ┆ 6.5 ┆ false │
|
3727
3606
|
# # └─────┴──────┴───────┴──────┴──────┴───────┘
|
3728
3607
|
def with_columns(exprs)
|
@@ -4105,14 +3984,13 @@ module Polars
|
|
4105
3984
|
# # │ u8 ┆ u8 ┆ u8 ┆ u8 ┆ u8 ┆ u8 │
|
4106
3985
|
# # ╞═══════╪═══════╪═══════╪═══════╪═══════╪═══════╡
|
4107
3986
|
# # │ 1 ┆ 0 ┆ 1 ┆ 0 ┆ 1 ┆ 0 │
|
4108
|
-
# # ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
4109
3987
|
# # │ 0 ┆ 1 ┆ 0 ┆ 1 ┆ 0 ┆ 1 │
|
4110
3988
|
# # └───────┴───────┴───────┴───────┴───────┴───────┘
|
4111
|
-
def to_dummies(columns: nil)
|
3989
|
+
def to_dummies(columns: nil, separator: "_")
|
4112
3990
|
if columns.is_a?(String)
|
4113
3991
|
columns = [columns]
|
4114
3992
|
end
|
4115
|
-
_from_rbdf(_df.to_dummies(columns))
|
3993
|
+
_from_rbdf(_df.to_dummies(columns, separator))
|
4116
3994
|
end
|
4117
3995
|
|
4118
3996
|
# Drop duplicate rows from this DataFrame.
|
@@ -4148,13 +4026,9 @@ module Polars
|
|
4148
4026
|
# # │ i64 ┆ f64 ┆ bool │
|
4149
4027
|
# # ╞═════╪═════╪═══════╡
|
4150
4028
|
# # │ 1 ┆ 0.5 ┆ true │
|
4151
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
4152
4029
|
# # │ 2 ┆ 1.0 ┆ true │
|
4153
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
4154
4030
|
# # │ 3 ┆ 2.0 ┆ false │
|
4155
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
4156
4031
|
# # │ 4 ┆ 3.0 ┆ true │
|
4157
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
4158
4032
|
# # │ 5 ┆ 3.0 ┆ true │
|
4159
4033
|
# # └─────┴─────┴───────┘
|
4160
4034
|
def unique(maintain_order: true, subset: nil, keep: "first")
|
@@ -4288,7 +4162,6 @@ module Polars
|
|
4288
4162
|
# # │ i64 ┆ i64 ┆ str │
|
4289
4163
|
# # ╞═════╪═════╪═════╡
|
4290
4164
|
# # │ 3 ┆ 8 ┆ c │
|
4291
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
4292
4165
|
# # │ 2 ┆ 7 ┆ b │
|
4293
4166
|
# # └─────┴─────┴─────┘
|
4294
4167
|
def sample(
|
@@ -4408,6 +4281,10 @@ module Polars
|
|
4408
4281
|
# Row index.
|
4409
4282
|
# @param by_predicate [Object]
|
4410
4283
|
# Select the row according to a given expression/predicate.
|
4284
|
+
# @param named [Boolean]
|
4285
|
+
# Return a hash instead of an array. The hash is a mapping of
|
4286
|
+
# column name to row value. This is more expensive than returning an
|
4287
|
+
# array, but allows for accessing values by column name.
|
4411
4288
|
#
|
4412
4289
|
# @return [Object]
|
4413
4290
|
#
|
@@ -4430,25 +4307,44 @@ module Polars
|
|
4430
4307
|
# df.row(2)
|
4431
4308
|
# # => [3, 8, "c"]
|
4432
4309
|
#
|
4310
|
+
# @example Get a hash instead with a mapping of column names to row values
|
4311
|
+
# df.row(2, named: true)
|
4312
|
+
# # => {"foo"=>3, "bar"=>8, "ham"=>"c"}
|
4313
|
+
#
|
4433
4314
|
# @example Return the row that matches the given predicate
|
4434
4315
|
# df.row(by_predicate: Polars.col("ham") == "b")
|
4435
4316
|
# # => [2, 7, "b"]
|
4436
|
-
def row(index = nil, by_predicate: nil)
|
4317
|
+
def row(index = nil, by_predicate: nil, named: false)
|
4437
4318
|
if !index.nil? && !by_predicate.nil?
|
4438
4319
|
raise ArgumentError, "Cannot set both 'index' and 'by_predicate'; mutually exclusive"
|
4439
4320
|
elsif index.is_a?(Expr)
|
4440
4321
|
raise TypeError, "Expressions should be passed to the 'by_predicate' param"
|
4441
|
-
|
4442
|
-
|
4443
|
-
|
4322
|
+
end
|
4323
|
+
|
4324
|
+
if !index.nil?
|
4325
|
+
row = _df.row_tuple(index)
|
4326
|
+
if named
|
4327
|
+
columns.zip(row).to_h
|
4328
|
+
else
|
4329
|
+
row
|
4330
|
+
end
|
4331
|
+
elsif !by_predicate.nil?
|
4332
|
+
if !by_predicate.is_a?(Expr)
|
4333
|
+
raise TypeError, "Expected by_predicate to be an expression; found #{by_predicate.class.name}"
|
4334
|
+
end
|
4444
4335
|
rows = filter(by_predicate).rows
|
4445
4336
|
n_rows = rows.length
|
4446
4337
|
if n_rows > 1
|
4447
4338
|
raise TooManyRowsReturned, "Predicate #{by_predicate} returned #{n_rows} rows"
|
4448
4339
|
elsif n_rows == 0
|
4449
|
-
raise NoRowsReturned, "Predicate
|
4340
|
+
raise NoRowsReturned, "Predicate #{by_predicate} returned no rows"
|
4341
|
+
end
|
4342
|
+
row = rows[0]
|
4343
|
+
if named
|
4344
|
+
columns.zip(row).to_h
|
4345
|
+
else
|
4346
|
+
row
|
4450
4347
|
end
|
4451
|
-
rows[0]
|
4452
4348
|
else
|
4453
4349
|
raise ArgumentError, "One of 'index' or 'by_predicate' must be set"
|
4454
4350
|
end
|
@@ -4456,6 +4352,11 @@ module Polars
|
|
4456
4352
|
|
4457
4353
|
# Convert columnar data to rows as Ruby arrays.
|
4458
4354
|
#
|
4355
|
+
# @param named [Boolean]
|
4356
|
+
# Return hashes instead of arrays. The hashes are a mapping of
|
4357
|
+
# column name to row value. This is more expensive than returning an
|
4358
|
+
# array, but allows for accessing values by column name.
|
4359
|
+
#
|
4459
4360
|
# @return [Array]
|
4460
4361
|
#
|
4461
4362
|
# @example
|
@@ -4467,8 +4368,79 @@ module Polars
|
|
4467
4368
|
# )
|
4468
4369
|
# df.rows
|
4469
4370
|
# # => [[1, 2], [3, 4], [5, 6]]
|
4470
|
-
|
4471
|
-
|
4371
|
+
# @example
|
4372
|
+
# df.rows(named: true)
|
4373
|
+
# # => [{"a"=>1, "b"=>2}, {"a"=>3, "b"=>4}, {"a"=>5, "b"=>6}]
|
4374
|
+
def rows(named: false)
|
4375
|
+
if named
|
4376
|
+
columns = columns()
|
4377
|
+
_df.row_tuples.map do |v|
|
4378
|
+
columns.zip(v).to_h
|
4379
|
+
end
|
4380
|
+
else
|
4381
|
+
_df.row_tuples
|
4382
|
+
end
|
4383
|
+
end
|
4384
|
+
|
4385
|
+
# Returns an iterator over the DataFrame of rows of python-native values.
|
4386
|
+
#
|
4387
|
+
# @param named [Boolean]
|
4388
|
+
# Return hashes instead of arrays. The hashes are a mapping of
|
4389
|
+
# column name to row value. This is more expensive than returning an
|
4390
|
+
# array, but allows for accessing values by column name.
|
4391
|
+
# @param buffer_size [Integer]
|
4392
|
+
# Determines the number of rows that are buffered internally while iterating
|
4393
|
+
# over the data; you should only modify this in very specific cases where the
|
4394
|
+
# default value is determined not to be a good fit to your access pattern, as
|
4395
|
+
# the speedup from using the buffer is significant (~2-4x). Setting this
|
4396
|
+
# value to zero disables row buffering.
|
4397
|
+
#
|
4398
|
+
# @return [Object]
|
4399
|
+
#
|
4400
|
+
# @example
|
4401
|
+
# df = Polars::DataFrame.new(
|
4402
|
+
# {
|
4403
|
+
# "a" => [1, 3, 5],
|
4404
|
+
# "b" => [2, 4, 6]
|
4405
|
+
# }
|
4406
|
+
# )
|
4407
|
+
# df.iter_rows.map { |row| row[0] }
|
4408
|
+
# # => [1, 3, 5]
|
4409
|
+
#
|
4410
|
+
# @example
|
4411
|
+
# df.iter_rows(named: true).map { |row| row["b"] }
|
4412
|
+
# # => [2, 4, 6]
|
4413
|
+
def iter_rows(named: false, buffer_size: 500, &block)
|
4414
|
+
return to_enum(:iter_rows, named: named, buffer_size: buffer_size) unless block_given?
|
4415
|
+
|
4416
|
+
# load into the local namespace for a modest performance boost in the hot loops
|
4417
|
+
columns = columns()
|
4418
|
+
|
4419
|
+
# note: buffering rows results in a 2-4x speedup over individual calls
|
4420
|
+
# to ".row(i)", so it should only be disabled in extremely specific cases.
|
4421
|
+
if buffer_size
|
4422
|
+
offset = 0
|
4423
|
+
while offset < height
|
4424
|
+
zerocopy_slice = slice(offset, buffer_size)
|
4425
|
+
rows_chunk = zerocopy_slice.rows(named: false)
|
4426
|
+
if named
|
4427
|
+
rows_chunk.each do |row|
|
4428
|
+
yield columns.zip(row).to_h
|
4429
|
+
end
|
4430
|
+
else
|
4431
|
+
rows_chunk.each(&block)
|
4432
|
+
end
|
4433
|
+
offset += buffer_size
|
4434
|
+
end
|
4435
|
+
elsif named
|
4436
|
+
height.times do |i|
|
4437
|
+
yield columns.zip(row(i)).to_h
|
4438
|
+
end
|
4439
|
+
else
|
4440
|
+
height.times do |i|
|
4441
|
+
yield row(i)
|
4442
|
+
end
|
4443
|
+
end
|
4472
4444
|
end
|
4473
4445
|
|
4474
4446
|
# Shrink DataFrame memory usage.
|
@@ -4502,7 +4474,6 @@ module Polars
|
|
4502
4474
|
# # │ i64 ┆ i64 │
|
4503
4475
|
# # ╞═════╪═════╡
|
4504
4476
|
# # │ 1 ┆ 5 │
|
4505
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌┤
|
4506
4477
|
# # │ 3 ┆ 7 │
|
4507
4478
|
# # └─────┴─────┘
|
4508
4479
|
def take_every(n)
|
@@ -4570,11 +4541,8 @@ module Polars
|
|
4570
4541
|
# # │ i64 ┆ i64 ┆ i64 │
|
4571
4542
|
# # ╞═════╪══════╪═════╡
|
4572
4543
|
# # │ 1 ┆ 6 ┆ 1 │
|
4573
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌┤
|
4574
4544
|
# # │ 5 ┆ 7 ┆ 3 │
|
4575
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌┤
|
4576
4545
|
# # │ 9 ┆ 9 ┆ 6 │
|
4577
|
-
# # ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌┤
|
4578
4546
|
# # │ 10 ┆ null ┆ 9 │
|
4579
4547
|
# # └─────┴──────┴─────┘
|
4580
4548
|
def interpolate
|
@@ -4655,7 +4623,6 @@ module Polars
|
|
4655
4623
|
# # │ str ┆ i64 ┆ str ┆ bool ┆ list[i64] ┆ str │
|
4656
4624
|
# # ╞════════╪═════╪═════╪══════╪═══════════╪═══════╡
|
4657
4625
|
# # │ foo ┆ 1 ┆ a ┆ true ┆ [1, 2] ┆ baz │
|
4658
|
-
# # ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
4659
4626
|
# # │ bar ┆ 2 ┆ b ┆ null ┆ [3] ┆ womp │
|
4660
4627
|
# # └────────┴─────┴─────┴──────┴───────────┴───────┘
|
4661
4628
|
def unnest(names)
|