polars-df 0.3.0-aarch64-linux → 0.3.1-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 149d64c6081571c49ebf70a596ee7f64763daf2a4aa8847587878e98b2739e7c
4
- data.tar.gz: 416d47f24b721a6dc1bfe1c770067ea5caa9f9131d26ecfb4d9502589bd72846
3
+ metadata.gz: 03146f4d688d578d073c3d7a18b06ec90ad625f2bad3e2c380d692b819237b2b
4
+ data.tar.gz: 84eb7c89fd428d31305f24e3593dcdcf6ece964deb75d704c6669658046ffe51
5
5
  SHA512:
6
- metadata.gz: c85491ed28c230dd515eee2206a061e0d1aee5bb43553001ad5b1061dd390747670517a3f78b0c528bbc34f61c64f2120d83811f6f1d0cadfa52f07ae34db49b
7
- data.tar.gz: c28b34e708314ec59721b110386789a974ecb048a27174edc7044015553bd0f9cf22ccb30b0a9233dce7db3d897379bb2673e89c335e830386c0313aae08011f
6
+ metadata.gz: 0fc21805cd8778ce2579150620bf22cf9fee107651d583b58696917356009760ece5ab07e72b9434efb19af7ef69eb10cd7707a04bdbad8393eb17f03adaa440
7
+ data.tar.gz: 50cb3d957b150cadd2e2578fdfaf0e20a66d03f31f69546e4478895e5c4758889ddfedba7d728b6c72d7f43b136b7705a807bf850509935c708bc71f171dde5a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.3.1 (2023-02-21)
2
+
3
+ - Added `to_numo` method to `Series` and `DataFrame`
4
+ - Added `plot` method to `DataFrame`
5
+ - Fixed `is_datelike` method for `Datetime` and `Duration`
6
+
1
7
  ## 0.3.0 (2023-02-15)
2
8
 
3
9
  - Updated Polars to 0.27.1
data/Cargo.lock CHANGED
@@ -1430,7 +1430,7 @@ dependencies = [
1430
1430
 
1431
1431
  [[package]]
1432
1432
  name = "polars"
1433
- version = "0.3.0"
1433
+ version = "0.3.1"
1434
1434
  dependencies = [
1435
1435
  "ahash",
1436
1436
  "jemallocator",
@@ -1626,33 +1626,6 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
1626
1626
  IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1627
1627
  DEALINGS IN THE SOFTWARE.
1628
1628
 
1629
- ================================================================================
1630
- array-init-cursor LICENSE-MIT
1631
- ================================================================================
1632
-
1633
- MIT License
1634
-
1635
- Copyright (c) 2021 The Planus Project Developers
1636
-
1637
- Permission is hereby granted, free of charge, to any person obtaining a copy
1638
- of this software and associated documentation files (the "Software"), to deal
1639
- in the Software without restriction, including without limitation the rights
1640
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1641
- copies of the Software, and to permit persons to whom the Software is
1642
- furnished to do so, subject to the following conditions:
1643
-
1644
- The above copyright notice and this permission notice shall be included in all
1645
- copies or substantial portions of the Software.
1646
-
1647
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1648
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1649
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1650
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1651
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1652
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1653
- SOFTWARE.
1654
-
1655
-
1656
1629
  ================================================================================
1657
1630
  array-init-cursor LICENSE-APACHE
1658
1631
  ================================================================================
@@ -1835,6 +1808,33 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1835
1808
  END OF TERMS AND CONDITIONS
1836
1809
 
1837
1810
 
1811
+ ================================================================================
1812
+ array-init-cursor LICENSE-MIT
1813
+ ================================================================================
1814
+
1815
+ MIT License
1816
+
1817
+ Copyright (c) 2021 The Planus Project Developers
1818
+
1819
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1820
+ of this software and associated documentation files (the "Software"), to deal
1821
+ in the Software without restriction, including without limitation the rights
1822
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1823
+ copies of the Software, and to permit persons to whom the Software is
1824
+ furnished to do so, subject to the following conditions:
1825
+
1826
+ The above copyright notice and this permission notice shall be included in all
1827
+ copies or substantial portions of the Software.
1828
+
1829
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1830
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1831
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1832
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1833
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1834
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1835
+ SOFTWARE.
1836
+
1837
+
1838
1838
  ================================================================================
1839
1839
  arrow-format LICENSE
1840
1840
  ================================================================================
@@ -15208,36 +15208,6 @@ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
15208
15208
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15209
15209
  --------------------------------------------------------------------------------
15210
15210
 
15211
- ================================================================================
15212
- jemallocator LICENSE-MIT
15213
- ================================================================================
15214
-
15215
- Copyright (c) 2014 Alex Crichton
15216
-
15217
- Permission is hereby granted, free of charge, to any
15218
- person obtaining a copy of this software and associated
15219
- documentation files (the "Software"), to deal in the
15220
- Software without restriction, including without
15221
- limitation the rights to use, copy, modify, merge,
15222
- publish, distribute, sublicense, and/or sell copies of
15223
- the Software, and to permit persons to whom the Software
15224
- is furnished to do so, subject to the following
15225
- conditions:
15226
-
15227
- The above copyright notice and this permission notice
15228
- shall be included in all copies or substantial portions
15229
- of the Software.
15230
-
15231
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
15232
- ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15233
- TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
15234
- PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
15235
- SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
15236
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
15237
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
15238
- IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
15239
- DEALINGS IN THE SOFTWARE.
15240
-
15241
15211
  ================================================================================
15242
15212
  jemallocator LICENSE-APACHE
15243
15213
  ================================================================================
@@ -15444,6 +15414,36 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15444
15414
  See the License for the specific language governing permissions and
15445
15415
  limitations under the License.
15446
15416
 
15417
+ ================================================================================
15418
+ jemallocator LICENSE-MIT
15419
+ ================================================================================
15420
+
15421
+ Copyright (c) 2014 Alex Crichton
15422
+
15423
+ Permission is hereby granted, free of charge, to any
15424
+ person obtaining a copy of this software and associated
15425
+ documentation files (the "Software"), to deal in the
15426
+ Software without restriction, including without
15427
+ limitation the rights to use, copy, modify, merge,
15428
+ publish, distribute, sublicense, and/or sell copies of
15429
+ the Software, and to permit persons to whom the Software
15430
+ is furnished to do so, subject to the following
15431
+ conditions:
15432
+
15433
+ The above copyright notice and this permission notice
15434
+ shall be included in all copies or substantial portions
15435
+ of the Software.
15436
+
15437
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
15438
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15439
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
15440
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
15441
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
15442
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
15443
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
15444
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
15445
+ DEALINGS IN THE SOFTWARE.
15446
+
15447
15447
  ================================================================================
15448
15448
  jobserver LICENSE-APACHE
15449
15449
  ================================================================================
@@ -27712,33 +27712,6 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27712
27712
  IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27713
27713
  DEALINGS IN THE SOFTWARE.
27714
27714
 
27715
- ================================================================================
27716
- planus LICENSE-MIT
27717
- ================================================================================
27718
-
27719
- MIT License
27720
-
27721
- Copyright (c) 2021 The Planus Project Developers
27722
-
27723
- Permission is hereby granted, free of charge, to any person obtaining a copy
27724
- of this software and associated documentation files (the "Software"), to deal
27725
- in the Software without restriction, including without limitation the rights
27726
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27727
- copies of the Software, and to permit persons to whom the Software is
27728
- furnished to do so, subject to the following conditions:
27729
-
27730
- The above copyright notice and this permission notice shall be included in all
27731
- copies or substantial portions of the Software.
27732
-
27733
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27734
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27735
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27736
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27737
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27738
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27739
- SOFTWARE.
27740
-
27741
-
27742
27715
  ================================================================================
27743
27716
  planus LICENSE-APACHE
27744
27717
  ================================================================================
@@ -27921,6 +27894,33 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
27921
27894
  END OF TERMS AND CONDITIONS
27922
27895
 
27923
27896
 
27897
+ ================================================================================
27898
+ planus LICENSE-MIT
27899
+ ================================================================================
27900
+
27901
+ MIT License
27902
+
27903
+ Copyright (c) 2021 The Planus Project Developers
27904
+
27905
+ Permission is hereby granted, free of charge, to any person obtaining a copy
27906
+ of this software and associated documentation files (the "Software"), to deal
27907
+ in the Software without restriction, including without limitation the rights
27908
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27909
+ copies of the Software, and to permit persons to whom the Software is
27910
+ furnished to do so, subject to the following conditions:
27911
+
27912
+ The above copyright notice and this permission notice shall be included in all
27913
+ copies or substantial portions of the Software.
27914
+
27915
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27916
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27917
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27918
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27919
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27920
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27921
+ SOFTWARE.
27922
+
27923
+
27924
27924
  ================================================================================
27925
27925
  polars LICENSE
27926
27926
  ================================================================================
data/README.md CHANGED
@@ -282,10 +282,10 @@ df.to_dummies
282
282
 
283
283
  ## Conversion
284
284
 
285
- Array of rows
285
+ Array of hashes
286
286
 
287
287
  ```ruby
288
- df.rows
288
+ df.rows(named: true)
289
289
  ```
290
290
 
291
291
  Hash of series
@@ -308,6 +308,12 @@ Parquet
308
308
  df.write_parquet("file.parquet")
309
309
  ```
310
310
 
311
+ Numo array
312
+
313
+ ```ruby
314
+ df.to_numo
315
+ ```
316
+
311
317
  ## Types
312
318
 
313
319
  You can specify column types when creating a data frame
@@ -343,6 +349,38 @@ Cast a column
343
349
  df["a"].cast(Polars::Int32)
344
350
  ```
345
351
 
352
+ ## Visualization
353
+
354
+ Add [Vega](https://github.com/ankane/vega-ruby) to your application’s Gemfile:
355
+
356
+ ```ruby
357
+ gem "vega"
358
+ ```
359
+
360
+ And use:
361
+
362
+ ```ruby
363
+ df.plot("a", "b")
364
+ ```
365
+
366
+ Specify the chart type (`line`, `pie`, `column`, `bar`, `area`, or `scatter`)
367
+
368
+ ```ruby
369
+ df.plot("a", "b", type: "pie")
370
+ ```
371
+
372
+ Group data
373
+
374
+ ```ruby
375
+ df.groupby("c").plot("a", "b")
376
+ ```
377
+
378
+ Stacked columns or bars
379
+
380
+ ```ruby
381
+ df.groupby("c").plot("a", "b", stacked: true)
382
+ ```
383
+
346
384
  ## History
347
385
 
348
386
  View the [changelog](CHANGELOG.md)
Binary file
Binary file
Binary file
@@ -1,6 +1,8 @@
1
1
  module Polars
2
2
  # Two-dimensional data structure representing data as a table with rows and columns.
3
3
  class DataFrame
4
+ include Plot
5
+
4
6
  # @private
5
7
  attr_accessor :_df
6
8
 
@@ -604,10 +606,10 @@ module Polars
604
606
  return Slice.new(self).apply(item)
605
607
  end
606
608
 
607
- if Utils.is_str_sequence(item, allow_str: false)
609
+ if item.is_a?(Array) && item.all? { |v| Utils.strlike?(v) }
608
610
  # select multiple columns
609
611
  # df[["foo", "bar"]]
610
- return _from_rbdf(_df.select(item))
612
+ return _from_rbdf(_df.select(item.map(&:to_s)))
611
613
  end
612
614
 
613
615
  if Utils.is_int_sequence(item)
@@ -689,7 +691,8 @@ module Polars
689
691
  # @example
690
692
  # df = Polars::DataFrame.new({"foo" => [1, 2, 3], "bar" => [4, 5, 6]})
691
693
  # df.to_hashes
692
- # [{'foo': 1, 'bar': 4}, {'foo': 2, 'bar': 5}, {'foo': 3, 'bar': 6}]
694
+ # # =>
695
+ # # [{"foo"=>1, "bar"=>4}, {"foo"=>2, "bar"=>5}, {"foo"=>3, "bar"=>6}]
693
696
  def to_hashes
694
697
  rbdf = _df
695
698
  names = columns
@@ -699,8 +702,26 @@ module Polars
699
702
  end
700
703
  end
701
704
 
702
- # def to_numo
703
- # end
705
+ # Convert DataFrame to a 2D Numo array.
706
+ #
707
+ # This operation clones data.
708
+ #
709
+ # @return [Numo::NArray]
710
+ #
711
+ # @example
712
+ # df = Polars::DataFrame.new(
713
+ # {"foo" => [1, 2, 3], "bar" => [6, 7, 8], "ham" => ["a", "b", "c"]}
714
+ # )
715
+ # df.to_numo.class
716
+ # # => Numo::RObject
717
+ def to_numo
718
+ out = _df.to_numo
719
+ if out.nil?
720
+ Numo::NArray.vstack(width.times.map { |i| to_series(i).to_numo }).transpose
721
+ else
722
+ out
723
+ end
724
+ end
704
725
 
705
726
  # no to_pandas
706
727
 
@@ -84,6 +84,8 @@ module Polars
84
84
 
85
85
  # Calendar date and time type.
86
86
  class Datetime < TemporalType
87
+ attr_reader :tu
88
+
87
89
  def initialize(time_unit = "us", time_zone = nil)
88
90
  @tu = time_unit || "us"
89
91
  @time_zone = time_zone
@@ -92,6 +94,8 @@ module Polars
92
94
 
93
95
  # Time duration/delta type.
94
96
  class Duration < TemporalType
97
+ attr_reader :tu
98
+
95
99
  def initialize(time_unit = "us")
96
100
  @tu = time_unit
97
101
  end
@@ -571,5 +571,16 @@ module Polars
571
571
  def agg_list
572
572
  agg(Polars.all.list)
573
573
  end
574
+
575
+ # Plot data.
576
+ #
577
+ # @return [Vega::LiteChart]
578
+ def plot(*args, **options)
579
+ raise ArgumentError, "Multiple groups not supported" if by.is_a?(Array) && by.size > 1
580
+ # same message as Ruby
581
+ raise ArgumentError, "unknown keyword: :group" if options.key?(:group)
582
+
583
+ Utils.wrap_df(_df).plot(*args, **options, group: by)
584
+ end
574
585
  end
575
586
  end
@@ -0,0 +1,109 @@
1
+ module Polars
2
+ module Plot
3
+ # Plot data.
4
+ #
5
+ # @return [Vega::LiteChart]
6
+ def plot(x = nil, y = nil, type: nil, group: nil, stacked: nil)
7
+ require "vega"
8
+
9
+ raise ArgumentError, "Must specify columns" if columns.size != 2 && (!x || !y)
10
+ x ||= columns[0]
11
+ y ||= columns[1]
12
+ type ||= begin
13
+ if self[x].numeric? && self[y].numeric?
14
+ "scatter"
15
+ elsif self[x].utf8? && self[y].numeric?
16
+ "column"
17
+ elsif (self[x].dtype == Date || self[x].dtype.is_a?(Datetime)) && self[y].numeric?
18
+ "line"
19
+ else
20
+ raise "Cannot determine type. Use the type option."
21
+ end
22
+ end
23
+ df = self[(group.nil? ? [x, y] : [x, y, group]).map(&:to_s).uniq]
24
+ data = df.rows(named: true)
25
+
26
+ case type
27
+ when "line", "area"
28
+ x_type =
29
+ if df[x].numeric?
30
+ "quantitative"
31
+ elsif df[x].datelike?
32
+ "temporal"
33
+ else
34
+ "nominal"
35
+ end
36
+
37
+ scale = x_type == "temporal" ? {type: "utc"} : {}
38
+ encoding = {
39
+ x: {field: x, type: x_type, scale: scale},
40
+ y: {field: y, type: "quantitative"}
41
+ }
42
+ encoding[:color] = {field: group} if group
43
+
44
+ Vega.lite
45
+ .data(data)
46
+ .mark(type: type, tooltip: true, interpolate: "cardinal", point: {size: 60})
47
+ .encoding(encoding)
48
+ .config(axis: {labelFontSize: 12})
49
+ when "pie"
50
+ raise ArgumentError, "Cannot use group option with pie chart" unless group.nil?
51
+
52
+ Vega.lite
53
+ .data(data)
54
+ .mark(type: "arc", tooltip: true)
55
+ .encoding(
56
+ color: {field: x, type: "nominal", sort: "none", axis: {title: nil}, legend: {labelFontSize: 12}},
57
+ theta: {field: y, type: "quantitative"}
58
+ )
59
+ .view(stroke: nil)
60
+ when "column"
61
+ encoding = {
62
+ x: {field: x, type: "nominal", sort: "none", axis: {labelAngle: 0}},
63
+ y: {field: y, type: "quantitative"}
64
+ }
65
+ if group
66
+ encoding[:color] = {field: group}
67
+ encoding[:xOffset] = {field: group} unless stacked
68
+ end
69
+
70
+ Vega.lite
71
+ .data(data)
72
+ .mark(type: "bar", tooltip: true)
73
+ .encoding(encoding)
74
+ .config(axis: {labelFontSize: 12})
75
+ when "bar"
76
+ encoding = {
77
+ # TODO determine label angle
78
+ y: {field: x, type: "nominal", sort: "none", axis: {labelAngle: 0}},
79
+ x: {field: y, type: "quantitative"}
80
+ }
81
+ if group
82
+ encoding[:color] = {field: group}
83
+ encoding[:yOffset] = {field: group} unless stacked
84
+ end
85
+
86
+ Vega.lite
87
+ .data(data)
88
+ .mark(type: "bar", tooltip: true)
89
+ .encoding(encoding)
90
+ .config(axis: {labelFontSize: 12})
91
+ when "scatter"
92
+ encoding = {
93
+ x: {field: x, type: "quantitative", scale: {zero: false}},
94
+ y: {field: y, type: "quantitative", scale: {zero: false}},
95
+ size: {value: 60}
96
+ }
97
+ encoding[:color] = {field: group} if group
98
+
99
+ Vega.lite
100
+ .data(data)
101
+ .mark(type: "circle", tooltip: true)
102
+ .encoding(encoding)
103
+ .config(axis: {labelFontSize: 12})
104
+ else
105
+ raise ArgumentError, "Invalid type: #{type}"
106
+ end
107
+ end
108
+ end
109
+ end
data/lib/polars/series.rb CHANGED
@@ -1776,8 +1776,9 @@ module Polars
1776
1776
  # s.is_datelike
1777
1777
  # # => true
1778
1778
  def is_datelike
1779
- [Date, Datetime, Duration, Time].include?(dtype)
1779
+ [Date, Time].include?(dtype) || dtype.is_a?(Datetime) || dtype.is_a?(Duration)
1780
1780
  end
1781
+ alias_method :datelike?, :is_datelike
1781
1782
 
1782
1783
  # Check if this Series has floating point numbers.
1783
1784
  #
@@ -1823,8 +1824,45 @@ module Polars
1823
1824
  # def view
1824
1825
  # end
1825
1826
 
1826
- # def to_numo
1827
- # end
1827
+ # Convert this Series to a Numo array. This operation clones data but is completely safe.
1828
+ #
1829
+ # @return [Numo::NArray]
1830
+ #
1831
+ # @example
1832
+ # s = Polars::Series.new("a", [1, 2, 3])
1833
+ # s.to_numo
1834
+ # # =>
1835
+ # # Numo::Int64#shape=[3]
1836
+ # # [1, 2, 3]
1837
+ def to_numo
1838
+ if !has_validity
1839
+ if is_datelike
1840
+ Numo::RObject.cast(to_a)
1841
+ elsif is_numeric
1842
+ # TODO make more efficient
1843
+ {
1844
+ UInt8 => Numo::UInt8,
1845
+ UInt16 => Numo::UInt16,
1846
+ UInt32 => Numo::UInt32,
1847
+ UInt64 => Numo::UInt64,
1848
+ Int8 => Numo::Int8,
1849
+ Int16 => Numo::Int16,
1850
+ Int32 => Numo::Int32,
1851
+ Int64 => Numo::Int64,
1852
+ Float32 => Numo::SFloat,
1853
+ Float64 => Numo::DFloat
1854
+ }.fetch(dtype).cast(to_a)
1855
+ elsif is_boolean
1856
+ Numo::Bit.cast(to_a)
1857
+ else
1858
+ _s.to_numo
1859
+ end
1860
+ elsif is_datelike
1861
+ Numo::RObject.cast(to_a)
1862
+ else
1863
+ _s.to_numo
1864
+ end
1865
+ end
1828
1866
 
1829
1867
  # Set masked values.
1830
1868
  #
@@ -1,4 +1,4 @@
1
1
  module Polars
2
2
  # @private
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
data/lib/polars.rb CHANGED
@@ -15,6 +15,7 @@ require_relative "polars/batched_csv_reader"
15
15
  require_relative "polars/cat_expr"
16
16
  require_relative "polars/cat_name_space"
17
17
  require_relative "polars/convert"
18
+ require_relative "polars/plot"
18
19
  require_relative "polars/data_frame"
19
20
  require_relative "polars/data_types"
20
21
  require_relative "polars/date_time_expr"
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.3.0
4
+ version: 0.3.1
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-16 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org
@@ -49,6 +49,7 @@ files:
49
49
  - lib/polars/list_expr.rb
50
50
  - lib/polars/list_name_space.rb
51
51
  - lib/polars/meta_expr.rb
52
+ - lib/polars/plot.rb
52
53
  - lib/polars/rolling_group_by.rb
53
54
  - lib/polars/series.rb
54
55
  - lib/polars/slice.rb