polars-df 0.4.0-x86_64-linux → 0.6.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,7 +25,7 @@ Polars.read_csv("iris.csv")
25
25
  .collect
26
26
  ```
27
27
 
28
- You can follow [Polars tutorials](https://pola-rs.github.io/polars-book/user-guide/introduction.html) and convert the code to Ruby in many cases. Feel free to open an issue if you run into problems.
28
+ You can follow [Polars tutorials](https://pola-rs.github.io/polars-book/user-guide/) and convert the code to Ruby in many cases. Feel free to open an issue if you run into problems.
29
29
 
30
30
  ## Reference
31
31
 
@@ -58,9 +58,9 @@ Polars.scan_parquet("file.parquet")
58
58
  From Active Record
59
59
 
60
60
  ```ruby
61
- Polars.read_sql(User.all)
61
+ Polars.read_database(User.all)
62
62
  # or
63
- Polars.read_sql("SELECT * FROM users")
63
+ Polars.read_database("SELECT * FROM users")
64
64
  ```
65
65
 
66
66
  From JSON
@@ -348,7 +348,7 @@ df.to_numo
348
348
  You can specify column types when creating a data frame
349
349
 
350
350
  ```ruby
351
- Polars::DataFrame.new(data, columns: {"a" => Polars::Int32, "b" => Polars::Float32})
351
+ Polars::DataFrame.new(data, schema: {"a" => Polars::Int32, "b" => Polars::Float32})
352
352
  ```
353
353
 
354
354
  Supported types are:
@@ -357,8 +357,9 @@ Supported types are:
357
357
  - float - `Float64`, `Float32`
358
358
  - integer - `Int64`, `Int32`, `Int16`, `Int8`
359
359
  - unsigned integer - `UInt64`, `UInt32`, `UInt16`, `UInt8`
360
- - string - `Utf8`, `Categorical`
360
+ - string - `Utf8`, `Binary`, `Categorical`
361
361
  - temporal - `Date`, `Datetime`, `Time`, `Duration`
362
+ - other - `Object`, `List`, `Struct`, `Array` [unreleased]
362
363
 
363
364
  Get column types
364
365
 
Binary file
Binary file
Binary file
@@ -0,0 +1,84 @@
1
+ module Polars
2
+ # Namespace for array related expressions.
3
+ class ArrayExpr
4
+ # @private
5
+ attr_accessor :_rbexpr
6
+
7
+ # @private
8
+ def initialize(expr)
9
+ self._rbexpr = expr._rbexpr
10
+ end
11
+
12
+ # Compute the min values of the sub-arrays.
13
+ #
14
+ # @return [Expr]
15
+ #
16
+ # @example
17
+ # df = Polars::DataFrame.new(
18
+ # {"a" => [[1, 2], [4, 3]]},
19
+ # schema: {"a" => Polars::Array.new(2, Polars::Int64)}
20
+ # )
21
+ # df.select(Polars.col("a").arr.min)
22
+ # # =>
23
+ # # shape: (2, 1)
24
+ # # ┌─────┐
25
+ # # │ a │
26
+ # # │ --- │
27
+ # # │ i64 │
28
+ # # ╞═════╡
29
+ # # │ 1 │
30
+ # # │ 3 │
31
+ # # └─────┘
32
+ def min
33
+ Utils.wrap_expr(_rbexpr.array_min)
34
+ end
35
+
36
+ # Compute the max values of the sub-arrays.
37
+ #
38
+ # @return [Expr]
39
+ #
40
+ # @example
41
+ # df = Polars::DataFrame.new(
42
+ # {"a" => [[1, 2], [4, 3]]},
43
+ # schema: {"a" => Polars::Array.new(2, Polars::Int64)}
44
+ # )
45
+ # df.select(Polars.col("a").arr.max)
46
+ # # =>
47
+ # # shape: (2, 1)
48
+ # # ┌─────┐
49
+ # # │ a │
50
+ # # │ --- │
51
+ # # │ i64 │
52
+ # # ╞═════╡
53
+ # # │ 2 │
54
+ # # │ 4 │
55
+ # # └─────┘
56
+ def max
57
+ Utils.wrap_expr(_rbexpr.array_max)
58
+ end
59
+
60
+ # Compute the sum values of the sub-arrays.
61
+ #
62
+ # @return [Expr]
63
+ #
64
+ # @example
65
+ # df = Polars::DataFrame.new(
66
+ # {"a" => [[1, 2], [4, 3]]},
67
+ # schema: {"a" => Polars::Array.new(2, Polars::Int64)}
68
+ # )
69
+ # df.select(Polars.col("a").arr.sum)
70
+ # # =>
71
+ # # shape: (2, 1)
72
+ # # ┌─────┐
73
+ # # │ a │
74
+ # # │ --- │
75
+ # # │ i64 │
76
+ # # ╞═════╡
77
+ # # │ 3 │
78
+ # # │ 7 │
79
+ # # └─────┘
80
+ def sum
81
+ Utils.wrap_expr(_rbexpr.array_sum)
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,77 @@
1
+ module Polars
2
+ # Series.arr namespace.
3
+ class ArrayNameSpace
4
+ include ExprDispatch
5
+
6
+ self._accessor = "arr"
7
+
8
+ # @private
9
+ def initialize(series)
10
+ self._s = series._s
11
+ end
12
+
13
+ # Compute the min values of the sub-arrays.
14
+ #
15
+ # @return [Series]
16
+ #
17
+ # @example
18
+ # s = Polars::Series.new(
19
+ # "a", [[1, 2], [4, 3]], dtype: Polars::Array.new(2, Polars::Int64)
20
+ # )
21
+ # s.arr.min
22
+ # # =>
23
+ # # shape: (2,)
24
+ # # Series: 'a' [i64]
25
+ # # [
26
+ # # 1
27
+ # # 3
28
+ # # ]
29
+ def min
30
+ super
31
+ end
32
+
33
+ # Compute the max values of the sub-arrays.
34
+ #
35
+ # @return [Series]
36
+ #
37
+ # @example
38
+ # s = Polars::Series.new(
39
+ # "a", [[1, 2], [4, 3]], dtype: Polars::Array.new(2, Polars::Int64)
40
+ # )
41
+ # s.arr.max
42
+ # # =>
43
+ # # shape: (2,)
44
+ # # Series: 'a' [i64]
45
+ # # [
46
+ # # 2
47
+ # # 4
48
+ # # ]
49
+ def max
50
+ super
51
+ end
52
+
53
+ # Compute the sum values of the sub-arrays.
54
+ #
55
+ # @return [Series]
56
+ #
57
+ # @example
58
+ # df = Polars::DataFrame.new(
59
+ # {"a" => [[1, 2], [4, 3]]},
60
+ # schema: {"a" => Polars::Array.new(2, Polars::Int64)}
61
+ # )
62
+ # df.select(Polars.col("a").arr.sum)
63
+ # # =>
64
+ # # shape: (2, 1)
65
+ # # ┌─────┐
66
+ # # │ a │
67
+ # # │ --- │
68
+ # # │ i64 │
69
+ # # ╞═════╡
70
+ # # │ 3 │
71
+ # # │ 7 │
72
+ # # └─────┘
73
+ def sum
74
+ super
75
+ end
76
+ end
77
+ end
@@ -41,7 +41,7 @@ module Polars
41
41
  dtypes.each do|k, v|
42
42
  dtype_list << [k, Utils.rb_type_to_dtype(v)]
43
43
  end
44
- elsif dtypes.is_a?(Array)
44
+ elsif dtypes.is_a?(::Array)
45
45
  dtype_slice = dtypes
46
46
  else
47
47
  raise ArgumentError, "dtype arg should be list or dict"
@@ -26,8 +26,8 @@ module Polars
26
26
  # # │ 1 ┆ 3 │
27
27
  # # │ 2 ┆ 4 │
28
28
  # # └─────┴─────┘
29
- def from_hash(data, columns: nil)
30
- DataFrame._from_hash(data, columns: columns)
29
+ def from_hash(data, schema: nil, columns: nil)
30
+ DataFrame._from_hash(data, schema: schema || columns)
31
31
  end
32
32
 
33
33
  # Construct a DataFrame from a sequence of dictionaries. This operation clones data.