polars-df 0.10.0-x86_64-linux-musl
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.
- checksums.yaml +7 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +175 -0
- data/Cargo.lock +2536 -0
- data/Cargo.toml +6 -0
- data/LICENSE-THIRD-PARTY.txt +38726 -0
- data/LICENSE.txt +20 -0
- data/README.md +437 -0
- data/lib/polars/3.1/polars.so +0 -0
- data/lib/polars/3.2/polars.so +0 -0
- data/lib/polars/3.3/polars.so +0 -0
- data/lib/polars/array_expr.rb +537 -0
- data/lib/polars/array_name_space.rb +423 -0
- data/lib/polars/batched_csv_reader.rb +98 -0
- data/lib/polars/binary_expr.rb +77 -0
- data/lib/polars/binary_name_space.rb +66 -0
- data/lib/polars/cat_expr.rb +72 -0
- data/lib/polars/cat_name_space.rb +125 -0
- data/lib/polars/config.rb +530 -0
- data/lib/polars/convert.rb +93 -0
- data/lib/polars/data_frame.rb +5418 -0
- data/lib/polars/data_types.rb +466 -0
- data/lib/polars/date_time_expr.rb +1444 -0
- data/lib/polars/date_time_name_space.rb +1484 -0
- data/lib/polars/dynamic_group_by.rb +52 -0
- data/lib/polars/exceptions.rb +31 -0
- data/lib/polars/expr.rb +6105 -0
- data/lib/polars/expr_dispatch.rb +22 -0
- data/lib/polars/functions/aggregation/horizontal.rb +246 -0
- data/lib/polars/functions/aggregation/vertical.rb +282 -0
- data/lib/polars/functions/as_datatype.rb +248 -0
- data/lib/polars/functions/col.rb +47 -0
- data/lib/polars/functions/eager.rb +182 -0
- data/lib/polars/functions/lazy.rb +1280 -0
- data/lib/polars/functions/len.rb +49 -0
- data/lib/polars/functions/lit.rb +35 -0
- data/lib/polars/functions/random.rb +16 -0
- data/lib/polars/functions/range/date_range.rb +103 -0
- data/lib/polars/functions/range/int_range.rb +51 -0
- data/lib/polars/functions/repeat.rb +144 -0
- data/lib/polars/functions/whenthen.rb +96 -0
- data/lib/polars/functions.rb +57 -0
- data/lib/polars/group_by.rb +548 -0
- data/lib/polars/io.rb +890 -0
- data/lib/polars/lazy_frame.rb +2833 -0
- data/lib/polars/lazy_group_by.rb +84 -0
- data/lib/polars/list_expr.rb +791 -0
- data/lib/polars/list_name_space.rb +445 -0
- data/lib/polars/meta_expr.rb +222 -0
- data/lib/polars/name_expr.rb +198 -0
- data/lib/polars/plot.rb +109 -0
- data/lib/polars/rolling_group_by.rb +37 -0
- data/lib/polars/series.rb +4527 -0
- data/lib/polars/slice.rb +104 -0
- data/lib/polars/sql_context.rb +194 -0
- data/lib/polars/string_cache.rb +75 -0
- data/lib/polars/string_expr.rb +1519 -0
- data/lib/polars/string_name_space.rb +810 -0
- data/lib/polars/struct_expr.rb +98 -0
- data/lib/polars/struct_name_space.rb +96 -0
- data/lib/polars/testing.rb +507 -0
- data/lib/polars/utils.rb +422 -0
- data/lib/polars/version.rb +4 -0
- data/lib/polars/whenthen.rb +83 -0
- data/lib/polars-df.rb +1 -0
- data/lib/polars.rb +72 -0
- 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
|