polars-df 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,45 @@
1
1
  module Polars
2
2
  module LazyFunctions
3
3
  def col(name)
4
- name = name.to_s if name.is_a?(Symbol)
5
- Utils.wrap_expr(RbExpr.col(name))
4
+ if name.is_a?(Series)
5
+ name = name.to_a
6
+ end
7
+
8
+ if name.is_a?(Array)
9
+ if name.length == 0 || name[0].is_a?(String) || name[0].is_a?(Symbol)
10
+ name = name.map { |v| v.is_a?(Symbol) ? v.to_s : v }
11
+ Utils.wrap_expr(RbExpr.cols(name))
12
+ elsif Utils.is_polars_dtype(name[0])
13
+ raise Todo
14
+ # Utils.wrap_expr(_dtype_cols(name))
15
+ else
16
+ raise ArgumentError, "Expected list values to be all `str` or all `DataType`"
17
+ end
18
+ else
19
+ name = name.to_s if name.is_a?(Symbol)
20
+ Utils.wrap_expr(RbExpr.col(name))
21
+ end
6
22
  end
7
23
 
8
24
  def element
9
25
  col("")
10
26
  end
11
27
 
28
+ def count(column = nil)
29
+ if column.nil?
30
+ return Utils.wrap_expr(RbExpr.count)
31
+ end
32
+
33
+ if column.is_a?(Series)
34
+ column.len
35
+ else
36
+ col(column).count
37
+ end
38
+ end
39
+
40
+ # def to_list
41
+ # end
42
+
12
43
  def std(column, ddof: 1)
13
44
  if column.is_a?(Series)
14
45
  column.std(ddof: ddof)
@@ -59,7 +90,7 @@ module Polars
59
90
  # TODO
60
91
  Utils.wrap_expr(_sum_exprs(exprs))
61
92
  else
62
- raise "todo"
93
+ raise Todo
63
94
  end
64
95
  end
65
96
 
@@ -83,10 +114,97 @@ module Polars
83
114
  end
84
115
  end
85
116
 
117
+ # def n_unique
118
+ # end
119
+
120
+ def first(column = nil)
121
+ if column.nil?
122
+ return Utils.wrap_expr(RbExpr.first)
123
+ end
124
+
125
+ if column.is_a?(Series)
126
+ if column.len > 0
127
+ column[0]
128
+ else
129
+ raise IndexError, "The series is empty, so no first value can be returned."
130
+ end
131
+ else
132
+ col(column).first
133
+ end
134
+ end
135
+
136
+ # def last
137
+ # end
138
+
139
+ # def head
140
+ # end
141
+
142
+ # def tail
143
+ # end
144
+
86
145
  def lit(value)
87
146
  Utils.wrap_expr(RbExpr.lit(value))
88
147
  end
89
148
 
149
+ # def cumsum
150
+ # end
151
+
152
+ # def spearman_rank_corr
153
+ # end
154
+
155
+ # def pearson_corr
156
+ # end
157
+
158
+ # def cov
159
+ # end
160
+
161
+ # def map
162
+ # end
163
+
164
+ # def apply
165
+ # end
166
+
167
+ def fold(acc, f, exprs)
168
+ acc = Utils.expr_to_lit_or_expr(acc, str_to_lit: true)
169
+ if exprs.is_a?(Expr)
170
+ exprs = [exprs]
171
+ end
172
+
173
+ exprs = Utils.selection_to_rbexpr_list(exprs)
174
+ Utils.wrap_expr(RbExpr.fold(acc._rbexpr, f, exprs))
175
+ end
176
+
177
+ # def reduce
178
+ # end
179
+
180
+ # def cumfold
181
+ # end
182
+
183
+ # def cumreduce
184
+ # end
185
+
186
+ # def any
187
+ # end
188
+
189
+ # def exclude
190
+ # end
191
+
192
+ def all(name = nil)
193
+ if name.nil?
194
+ col("*")
195
+ elsif name.is_a?(String) || name.is_a?(Symbol)
196
+ col(name).all
197
+ else
198
+ raise Todo
199
+ end
200
+ end
201
+
202
+ # def groups
203
+ # end
204
+
205
+ # def quantile
206
+ # end
207
+
90
208
  def arange(low, high, step: 1, eager: false, dtype: nil)
91
209
  low = Utils.expr_to_lit_or_expr(low, str_to_lit: false)
92
210
  high = Utils.expr_to_lit_or_expr(high, str_to_lit: false)
@@ -106,16 +224,41 @@ module Polars
106
224
  end
107
225
  end
108
226
 
109
- def all(name = nil)
110
- if name.nil?
111
- col("*")
112
- elsif name.is_a?(String) || name.is_a?(Symbol)
113
- col(name).all
114
- else
115
- raise "todo"
116
- end
227
+ # def argsort_by
228
+ # end
229
+
230
+ # def duration
231
+ # end
232
+
233
+ # def format
234
+ # end
235
+
236
+ def concat_list(exprs)
237
+ exprs = Utils.selection_to_rbexpr_list(exprs)
238
+ Utils.wrap_expr(RbExpr.concat_lst(exprs))
117
239
  end
118
240
 
241
+ # def collect_all
242
+ # end
243
+
244
+ # def select
245
+ # end
246
+
247
+ # def struct
248
+ # end
249
+
250
+ # def repeat
251
+ # end
252
+
253
+ # def arg_where
254
+ # end
255
+
256
+ # def coalesce
257
+ # end
258
+
259
+ # def from_epoch
260
+ # end
261
+
119
262
  def when(expr)
120
263
  expr = Utils.expr_to_lit_or_expr(expr)
121
264
  pw = RbExpr.when(expr._rbexpr)