polars-df 0.1.3 → 0.1.4

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.
@@ -0,0 +1,64 @@
1
+ module Polars
2
+ # Series.struct namespace.
3
+ class StructNameSpace
4
+ include ExprDispatch
5
+
6
+ self._accessor = "struct"
7
+
8
+ # @private
9
+ def initialize(series)
10
+ self._s = series._s
11
+ end
12
+
13
+ # Retrieve one of the fields of this `Struct` as a new Series.
14
+ #
15
+ # @return [Series]
16
+ def [](item)
17
+ if item.is_a?(Integer)
18
+ field(fields[item])
19
+ elsif item.is_a?(String)
20
+ field(item)
21
+ else
22
+ raise ArgumentError, "expected type Integer or String, got #{item.class.name}"
23
+ end
24
+ end
25
+
26
+ # Convert this Struct Series to a DataFrame.
27
+ #
28
+ # @return [DataFrame]
29
+ def to_frame
30
+ Utils.wrap_df(_s.struct_to_frame)
31
+ end
32
+
33
+ # Get the names of the fields.
34
+ #
35
+ # @return [Array]
36
+ def fields
37
+ if _s.nil?
38
+ []
39
+ else
40
+ _s.struct_fields
41
+ end
42
+ end
43
+
44
+ # Retrieve one of the fields of this `Struct` as a new Series.
45
+ #
46
+ # @param name [String]
47
+ # Name of the field
48
+ #
49
+ # @return [Series]
50
+ def field(name)
51
+ super
52
+ end
53
+
54
+ # Rename the fields of the struct.
55
+ #
56
+ # @param names [Array]
57
+ # New names in the order of the struct's fields
58
+ #
59
+ # @return [Series]
60
+ def rename_fields(names)
61
+ super
62
+ end
63
+ end
64
+ end
data/lib/polars/utils.rb CHANGED
@@ -37,6 +37,34 @@ module Polars
37
37
  end
38
38
  end
39
39
 
40
+ def self._to_ruby_datetime(value, dtype, tu: "ns", tz: nil)
41
+ if dtype == :date
42
+ # days to seconds
43
+ # important to create from utc. Not doing this leads
44
+ # to inconsistencies dependent on the timezone you are in.
45
+ Time.at(value * 86400).utc.to_date
46
+ # TODO fix dtype
47
+ elsif dtype.to_s.start_with?("datetime[")
48
+ if tz.nil? || tz == ""
49
+ if tu == "ns"
50
+ raise Todo
51
+ elsif tu == "us"
52
+ dt = Time.at(value / 1000000, value % 1000000, :usec).utc
53
+ elsif tu == "ms"
54
+ raise Todo
55
+ else
56
+ raise ArgumentError, "tu must be one of {{'ns', 'us', 'ms'}}, got #{tu}"
57
+ end
58
+ else
59
+ raise Todo
60
+ end
61
+
62
+ dt
63
+ else
64
+ raise NotImplementedError
65
+ end
66
+ end
67
+
40
68
  def self.selection_to_rbexpr_list(exprs)
41
69
  if exprs.is_a?(String) || exprs.is_a?(Expr) || exprs.is_a?(Series)
42
70
  exprs = [exprs]
@@ -1,4 +1,4 @@
1
1
  module Polars
2
2
  # @private
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
data/lib/polars.rb CHANGED
@@ -8,8 +8,10 @@ require "date"
8
8
  require "polars/expr_dispatch"
9
9
  require "polars/batched_csv_reader"
10
10
  require "polars/cat_expr"
11
+ require "polars/cat_name_space"
11
12
  require "polars/data_frame"
12
13
  require "polars/date_time_expr"
14
+ require "polars/date_time_name_space"
13
15
  require "polars/exceptions"
14
16
  require "polars/expr"
15
17
  require "polars/functions"
@@ -19,11 +21,14 @@ require "polars/lazy_frame"
19
21
  require "polars/lazy_functions"
20
22
  require "polars/lazy_group_by"
21
23
  require "polars/list_expr"
24
+ require "polars/list_name_space"
22
25
  require "polars/meta_expr"
23
26
  require "polars/series"
24
27
  require "polars/slice"
25
28
  require "polars/string_expr"
29
+ require "polars/string_name_space"
26
30
  require "polars/struct_expr"
31
+ require "polars/struct_name_space"
27
32
  require "polars/utils"
28
33
  require "polars/version"
29
34
  require "polars/when"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polars-df
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-28 00:00:00.000000000 Z
11
+ date: 2022-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys
@@ -51,6 +51,7 @@ files:
51
51
  - ext/polars/src/lazy/mod.rs
52
52
  - ext/polars/src/lazy/utils.rs
53
53
  - ext/polars/src/lib.rs
54
+ - ext/polars/src/list_construction.rs
54
55
  - ext/polars/src/series.rs
55
56
  - ext/polars/src/set.rs
56
57
  - ext/polars/src/utils.rs
@@ -58,8 +59,10 @@ files:
58
59
  - lib/polars.rb
59
60
  - lib/polars/batched_csv_reader.rb
60
61
  - lib/polars/cat_expr.rb
62
+ - lib/polars/cat_name_space.rb
61
63
  - lib/polars/data_frame.rb
62
64
  - lib/polars/date_time_expr.rb
65
+ - lib/polars/date_time_name_space.rb
63
66
  - lib/polars/exceptions.rb
64
67
  - lib/polars/expr.rb
65
68
  - lib/polars/expr_dispatch.rb
@@ -70,11 +73,14 @@ files:
70
73
  - lib/polars/lazy_functions.rb
71
74
  - lib/polars/lazy_group_by.rb
72
75
  - lib/polars/list_expr.rb
76
+ - lib/polars/list_name_space.rb
73
77
  - lib/polars/meta_expr.rb
74
78
  - lib/polars/series.rb
75
79
  - lib/polars/slice.rb
76
80
  - lib/polars/string_expr.rb
81
+ - lib/polars/string_name_space.rb
77
82
  - lib/polars/struct_expr.rb
83
+ - lib/polars/struct_name_space.rb
78
84
  - lib/polars/utils.rb
79
85
  - lib/polars/version.rb
80
86
  - lib/polars/when.rb