polars-df 0.10.0-x86_64-linux-musl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +3 -0
  3. data/CHANGELOG.md +175 -0
  4. data/Cargo.lock +2536 -0
  5. data/Cargo.toml +6 -0
  6. data/LICENSE-THIRD-PARTY.txt +38726 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +437 -0
  9. data/lib/polars/3.1/polars.so +0 -0
  10. data/lib/polars/3.2/polars.so +0 -0
  11. data/lib/polars/3.3/polars.so +0 -0
  12. data/lib/polars/array_expr.rb +537 -0
  13. data/lib/polars/array_name_space.rb +423 -0
  14. data/lib/polars/batched_csv_reader.rb +98 -0
  15. data/lib/polars/binary_expr.rb +77 -0
  16. data/lib/polars/binary_name_space.rb +66 -0
  17. data/lib/polars/cat_expr.rb +72 -0
  18. data/lib/polars/cat_name_space.rb +125 -0
  19. data/lib/polars/config.rb +530 -0
  20. data/lib/polars/convert.rb +93 -0
  21. data/lib/polars/data_frame.rb +5418 -0
  22. data/lib/polars/data_types.rb +466 -0
  23. data/lib/polars/date_time_expr.rb +1444 -0
  24. data/lib/polars/date_time_name_space.rb +1484 -0
  25. data/lib/polars/dynamic_group_by.rb +52 -0
  26. data/lib/polars/exceptions.rb +31 -0
  27. data/lib/polars/expr.rb +6105 -0
  28. data/lib/polars/expr_dispatch.rb +22 -0
  29. data/lib/polars/functions/aggregation/horizontal.rb +246 -0
  30. data/lib/polars/functions/aggregation/vertical.rb +282 -0
  31. data/lib/polars/functions/as_datatype.rb +248 -0
  32. data/lib/polars/functions/col.rb +47 -0
  33. data/lib/polars/functions/eager.rb +182 -0
  34. data/lib/polars/functions/lazy.rb +1280 -0
  35. data/lib/polars/functions/len.rb +49 -0
  36. data/lib/polars/functions/lit.rb +35 -0
  37. data/lib/polars/functions/random.rb +16 -0
  38. data/lib/polars/functions/range/date_range.rb +103 -0
  39. data/lib/polars/functions/range/int_range.rb +51 -0
  40. data/lib/polars/functions/repeat.rb +144 -0
  41. data/lib/polars/functions/whenthen.rb +96 -0
  42. data/lib/polars/functions.rb +57 -0
  43. data/lib/polars/group_by.rb +548 -0
  44. data/lib/polars/io.rb +890 -0
  45. data/lib/polars/lazy_frame.rb +2833 -0
  46. data/lib/polars/lazy_group_by.rb +84 -0
  47. data/lib/polars/list_expr.rb +791 -0
  48. data/lib/polars/list_name_space.rb +445 -0
  49. data/lib/polars/meta_expr.rb +222 -0
  50. data/lib/polars/name_expr.rb +198 -0
  51. data/lib/polars/plot.rb +109 -0
  52. data/lib/polars/rolling_group_by.rb +37 -0
  53. data/lib/polars/series.rb +4527 -0
  54. data/lib/polars/slice.rb +104 -0
  55. data/lib/polars/sql_context.rb +194 -0
  56. data/lib/polars/string_cache.rb +75 -0
  57. data/lib/polars/string_expr.rb +1519 -0
  58. data/lib/polars/string_name_space.rb +810 -0
  59. data/lib/polars/struct_expr.rb +98 -0
  60. data/lib/polars/struct_name_space.rb +96 -0
  61. data/lib/polars/testing.rb +507 -0
  62. data/lib/polars/utils.rb +422 -0
  63. data/lib/polars/version.rb +4 -0
  64. data/lib/polars/whenthen.rb +83 -0
  65. data/lib/polars-df.rb +1 -0
  66. data/lib/polars.rb +72 -0
  67. metadata +125 -0
@@ -0,0 +1,72 @@
1
+ module Polars
2
+ # Namespace for categorical related expressions.
3
+ class CatExpr
4
+ # @private
5
+ attr_accessor :_rbexpr
6
+
7
+ # @private
8
+ def initialize(expr)
9
+ self._rbexpr = expr._rbexpr
10
+ end
11
+
12
+ # Determine how this categorical series should be sorted.
13
+ #
14
+ # @param ordering ["physical", "lexical"]
15
+ # Ordering type:
16
+ #
17
+ # - 'physical' -> Use the physical representation of the categories to determine the order (default).
18
+ # - 'lexical' -> Use the string values to determine the ordering.
19
+ #
20
+ # @return [Expr]
21
+ #
22
+ # @example
23
+ # df = Polars::DataFrame.new(
24
+ # {"cats" => ["z", "z", "k", "a", "b"], "vals" => [3, 1, 2, 2, 3]}
25
+ # ).with_columns(
26
+ # [
27
+ # Polars.col("cats").cast(:cat).cat.set_ordering("lexical")
28
+ # ]
29
+ # )
30
+ # df.sort(["cats", "vals"])
31
+ # # =>
32
+ # # shape: (5, 2)
33
+ # # ┌──────┬──────┐
34
+ # # │ cats ┆ vals │
35
+ # # │ --- ┆ --- │
36
+ # # │ cat ┆ i64 │
37
+ # # ╞══════╪══════╡
38
+ # # │ a ┆ 2 │
39
+ # # │ b ┆ 3 │
40
+ # # │ k ┆ 2 │
41
+ # # │ z ┆ 1 │
42
+ # # │ z ┆ 3 │
43
+ # # └──────┴──────┘
44
+ def set_ordering(ordering)
45
+ Utils.wrap_expr(_rbexpr.cat_set_ordering(ordering))
46
+ end
47
+
48
+ # Get the categories stored in this data type.
49
+ #
50
+ # @return [Expr]
51
+ #
52
+ # @example
53
+ # df = Polars::Series.new(
54
+ # "cats", ["foo", "bar", "foo", "foo", "ham"], dtype: Polars::Categorical
55
+ # ).to_frame
56
+ # df.select(Polars.col("cats").cat.get_categories)
57
+ # # =>
58
+ # # shape: (3, 1)
59
+ # # ┌──────┐
60
+ # # │ cats │
61
+ # # │ --- │
62
+ # # │ str │
63
+ # # ╞══════╡
64
+ # # │ foo │
65
+ # # │ bar │
66
+ # # │ ham │
67
+ # # └──────┘
68
+ def get_categories
69
+ Utils.wrap_expr(_rbexpr.cat_get_categories)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,125 @@
1
+ module Polars
2
+ # Series.cat namespace.
3
+ class CatNameSpace
4
+ include ExprDispatch
5
+
6
+ self._accessor = "cat"
7
+
8
+ # @private
9
+ def initialize(series)
10
+ self._s = series._s
11
+ end
12
+
13
+ # Determine how this categorical series should be sorted.
14
+ #
15
+ # @param ordering ["physical", "lexical"]
16
+ # Ordering type:
17
+ #
18
+ # - 'physical' -> Use the physical representation of the categories to
19
+ # determine the order (default).
20
+ # - 'lexical' -> Use the string values to determine the ordering.
21
+ #
22
+ # @return [Series]
23
+ #
24
+ # @example
25
+ # df = Polars::DataFrame.new(
26
+ # {"cats" => ["z", "z", "k", "a", "b"], "vals" => [3, 1, 2, 2, 3]}
27
+ # ).with_columns(
28
+ # [
29
+ # Polars.col("cats").cast(:cat).cat.set_ordering("lexical")
30
+ # ]
31
+ # )
32
+ # df.sort(["cats", "vals"])
33
+ # # =>
34
+ # # shape: (5, 2)
35
+ # # ┌──────┬──────┐
36
+ # # │ cats ┆ vals │
37
+ # # │ --- ┆ --- │
38
+ # # │ cat ┆ i64 │
39
+ # # ╞══════╪══════╡
40
+ # # │ a ┆ 2 │
41
+ # # │ b ┆ 3 │
42
+ # # │ k ┆ 2 │
43
+ # # │ z ┆ 1 │
44
+ # # │ z ┆ 3 │
45
+ # # └──────┴──────┘
46
+ def set_ordering(ordering)
47
+ super
48
+ end
49
+
50
+ # Get the categories stored in this data type.
51
+ #
52
+ # @return [Series]
53
+ #
54
+ # @example
55
+ # s = Polars::Series.new(["foo", "bar", "foo", "foo", "ham"], dtype: Polars::Categorical)
56
+ # s.cat.get_categories
57
+ # # =>
58
+ # # shape: (3,)
59
+ # # Series: '' [str]
60
+ # # [
61
+ # # "foo"
62
+ # # "bar"
63
+ # # "ham"
64
+ # # ]
65
+ def get_categories
66
+ super
67
+ end
68
+
69
+ # Return whether or not the column is a local categorical.
70
+ #
71
+ # @return [Boolean]
72
+ #
73
+ # @example Categoricals constructed without a string cache are considered local.
74
+ # s = Polars::Series.new(["a", "b", "a"], dtype: Polars::Categorical)
75
+ # s.cat.is_local
76
+ # # => true
77
+ #
78
+ # @example Categoricals constructed with a string cache are considered global.
79
+ # s = nil
80
+ # Polars::StringCache.new do
81
+ # s = Polars::Series.new(["a", "b", "a"], dtype: Polars::Categorical)
82
+ # end
83
+ # s.cat.is_local
84
+ # # => false
85
+ def is_local
86
+ _s.cat_is_local
87
+ end
88
+
89
+ # Convert a categorical column to its local representation.
90
+ #
91
+ # This may change the underlying physical representation of the column.
92
+ #
93
+ # @return [Series]
94
+ #
95
+ # @example Compare the global and local representations of a categorical.
96
+ # s = nil
97
+ # Polars::StringCache.new do
98
+ # _ = Polars::Series.new("x", ["a", "b", "a"], dtype: Polars::Categorical)
99
+ # s = Polars::Series.new("y", ["c", "b", "d"], dtype: Polars::Categorical)
100
+ # end
101
+ # s.to_physical
102
+ # # =>
103
+ # # shape: (3,)
104
+ # # Series: 'y' [u32]
105
+ # # [
106
+ # # 2
107
+ # # 1
108
+ # # 3
109
+ # # ]
110
+ #
111
+ # @example
112
+ # s.cat.to_local.to_physical
113
+ # # =>
114
+ # # shape: (3,)
115
+ # # Series: 'y' [u32]
116
+ # # [
117
+ # # 0
118
+ # # 1
119
+ # # 2
120
+ # # ]
121
+ def to_local
122
+ Utils.wrap_s(_s.cat_to_local)
123
+ end
124
+ end
125
+ end