polars-df 0.13.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/Cargo.lock +1368 -319
- data/LICENSE.txt +1 -0
- data/README.md +1 -2
- data/ext/polars/Cargo.toml +15 -6
- data/ext/polars/src/batched_csv.rs +10 -13
- data/ext/polars/src/conversion/any_value.rs +37 -21
- data/ext/polars/src/conversion/chunked_array.rs +3 -3
- data/ext/polars/src/conversion/mod.rs +159 -46
- data/ext/polars/src/dataframe/construction.rs +4 -7
- data/ext/polars/src/dataframe/export.rs +9 -2
- data/ext/polars/src/dataframe/general.rs +22 -16
- data/ext/polars/src/dataframe/io.rs +78 -174
- data/ext/polars/src/dataframe/mod.rs +1 -0
- data/ext/polars/src/dataframe/serde.rs +15 -0
- data/ext/polars/src/error.rs +31 -48
- data/ext/polars/src/exceptions.rs +24 -0
- data/ext/polars/src/expr/binary.rs +4 -42
- data/ext/polars/src/expr/datetime.rs +16 -7
- data/ext/polars/src/expr/general.rs +14 -23
- data/ext/polars/src/expr/list.rs +18 -11
- data/ext/polars/src/expr/name.rs +3 -2
- data/ext/polars/src/expr/rolling.rs +6 -7
- data/ext/polars/src/expr/string.rs +17 -37
- data/ext/polars/src/file.rs +59 -22
- data/ext/polars/src/functions/business.rs +15 -0
- data/ext/polars/src/functions/io.rs +6 -6
- data/ext/polars/src/functions/lazy.rs +17 -8
- data/ext/polars/src/functions/mod.rs +1 -0
- data/ext/polars/src/functions/range.rs +4 -2
- data/ext/polars/src/interop/arrow/mod.rs +1 -0
- data/ext/polars/src/interop/arrow/to_ruby.rs +83 -0
- data/ext/polars/src/interop/mod.rs +1 -0
- data/ext/polars/src/lazyframe/general.rs +877 -0
- data/ext/polars/src/lazyframe/mod.rs +3 -825
- data/ext/polars/src/lazyframe/serde.rs +31 -0
- data/ext/polars/src/lib.rs +44 -13
- data/ext/polars/src/map/dataframe.rs +46 -14
- data/ext/polars/src/map/lazy.rs +65 -4
- data/ext/polars/src/map/mod.rs +17 -16
- data/ext/polars/src/map/series.rs +106 -64
- data/ext/polars/src/on_startup.rs +2 -2
- data/ext/polars/src/series/aggregation.rs +1 -5
- data/ext/polars/src/series/arithmetic.rs +10 -10
- data/ext/polars/src/series/construction.rs +52 -25
- data/ext/polars/src/series/export.rs +1 -1
- data/ext/polars/src/series/general.rs +643 -0
- data/ext/polars/src/series/import.rs +55 -0
- data/ext/polars/src/series/mod.rs +11 -638
- data/ext/polars/src/series/scatter.rs +2 -2
- data/ext/polars/src/utils.rs +0 -20
- data/lib/polars/batched_csv_reader.rb +0 -2
- data/lib/polars/binary_expr.rb +133 -9
- data/lib/polars/binary_name_space.rb +101 -6
- data/lib/polars/config.rb +4 -0
- data/lib/polars/data_frame.rb +285 -62
- data/lib/polars/data_type_group.rb +28 -0
- data/lib/polars/data_types.rb +2 -0
- data/lib/polars/date_time_expr.rb +244 -0
- data/lib/polars/date_time_name_space.rb +87 -0
- data/lib/polars/expr.rb +109 -8
- data/lib/polars/functions/as_datatype.rb +51 -2
- data/lib/polars/functions/col.rb +1 -1
- data/lib/polars/functions/eager.rb +1 -3
- data/lib/polars/functions/lazy.rb +88 -10
- data/lib/polars/functions/range/time_range.rb +21 -21
- data/lib/polars/io/csv.rb +14 -16
- data/lib/polars/io/database.rb +2 -2
- data/lib/polars/io/ipc.rb +14 -12
- data/lib/polars/io/ndjson.rb +10 -0
- data/lib/polars/io/parquet.rb +168 -111
- data/lib/polars/lazy_frame.rb +649 -15
- data/lib/polars/list_name_space.rb +169 -0
- data/lib/polars/selectors.rb +1144 -0
- data/lib/polars/series.rb +470 -40
- data/lib/polars/string_cache.rb +27 -1
- data/lib/polars/string_expr.rb +0 -1
- data/lib/polars/string_name_space.rb +73 -3
- data/lib/polars/struct_name_space.rb +31 -7
- data/lib/polars/utils/various.rb +5 -1
- data/lib/polars/utils.rb +45 -10
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +2 -1
- metadata +14 -4
- data/lib/polars/functions.rb +0 -57
data/lib/polars/series.rb
CHANGED
@@ -88,6 +88,11 @@ module Polars
|
|
88
88
|
# Get the data type of this Series.
|
89
89
|
#
|
90
90
|
# @return [Symbol]
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# s = Polars::Series.new("a", [1, 2, 3])
|
94
|
+
# s.dtype
|
95
|
+
# # => Polars::Int64
|
91
96
|
def dtype
|
92
97
|
_s.dtype
|
93
98
|
end
|
@@ -95,6 +100,11 @@ module Polars
|
|
95
100
|
# Get flags that are set on the Series.
|
96
101
|
#
|
97
102
|
# @return [Hash]
|
103
|
+
#
|
104
|
+
# @example
|
105
|
+
# s = Polars::Series.new("a", [1, 2, 3])
|
106
|
+
# s.flags
|
107
|
+
# # => {"SORTED_ASC"=>false, "SORTED_DESC"=>false}
|
98
108
|
def flags
|
99
109
|
out = {
|
100
110
|
"SORTED_ASC" => _s.is_sorted_flag,
|
@@ -106,16 +116,14 @@ module Polars
|
|
106
116
|
out
|
107
117
|
end
|
108
118
|
|
109
|
-
# Get the inner dtype in of a List typed Series.
|
110
|
-
#
|
111
|
-
# @return [Symbol]
|
112
|
-
def inner_dtype
|
113
|
-
_s.inner_dtype
|
114
|
-
end
|
115
|
-
|
116
119
|
# Get the name of this Series.
|
117
120
|
#
|
118
121
|
# @return [String]
|
122
|
+
#
|
123
|
+
# @example
|
124
|
+
# s = Polars::Series.new("a", [1, 2, 3])
|
125
|
+
# s.name
|
126
|
+
# # => "a"
|
119
127
|
def name
|
120
128
|
_s.name
|
121
129
|
end
|
@@ -123,17 +131,15 @@ module Polars
|
|
123
131
|
# Shape of this Series.
|
124
132
|
#
|
125
133
|
# @return [Array]
|
134
|
+
#
|
135
|
+
# @example
|
136
|
+
# s = Polars::Series.new("a", [1, 2, 3])
|
137
|
+
# s.shape
|
138
|
+
# # => [3]
|
126
139
|
def shape
|
127
140
|
[_s.len]
|
128
141
|
end
|
129
142
|
|
130
|
-
# Get the time unit of underlying Datetime Series as `"ns"`, `"us"`, or `"ms"`.
|
131
|
-
#
|
132
|
-
# @return [String]
|
133
|
-
def time_unit
|
134
|
-
_s.time_unit
|
135
|
-
end
|
136
|
-
|
137
143
|
# Returns a string representing the Series.
|
138
144
|
#
|
139
145
|
# @return [String]
|
@@ -524,6 +530,18 @@ module Polars
|
|
524
530
|
# Compute the square root of the elements.
|
525
531
|
#
|
526
532
|
# @return [Series]
|
533
|
+
#
|
534
|
+
# @example
|
535
|
+
# s = Polars::Series.new([1, 2, 3])
|
536
|
+
# s.sqrt
|
537
|
+
# # =>
|
538
|
+
# # shape: (3,)
|
539
|
+
# # Series: '' [f64]
|
540
|
+
# # [
|
541
|
+
# # 1.0
|
542
|
+
# # 1.414214
|
543
|
+
# # 1.732051
|
544
|
+
# # ]
|
527
545
|
def sqrt
|
528
546
|
self**0.5
|
529
547
|
end
|
@@ -531,6 +549,18 @@ module Polars
|
|
531
549
|
# Check if any boolean value in the column is `true`.
|
532
550
|
#
|
533
551
|
# @return [Boolean]
|
552
|
+
#
|
553
|
+
# @example
|
554
|
+
# Polars::Series.new([true, false]).any?
|
555
|
+
# # => true
|
556
|
+
#
|
557
|
+
# @example
|
558
|
+
# Polars::Series.new([false, false]).any?
|
559
|
+
# # => false
|
560
|
+
#
|
561
|
+
# @example
|
562
|
+
# Polars::Series.new([nil, false]).any?
|
563
|
+
# # => false
|
534
564
|
def any?(ignore_nulls: true, &block)
|
535
565
|
if block_given?
|
536
566
|
apply(skip_nulls: ignore_nulls, &block).any?
|
@@ -543,6 +573,18 @@ module Polars
|
|
543
573
|
# Check if all boolean values in the column are `true`.
|
544
574
|
#
|
545
575
|
# @return [Boolean]
|
576
|
+
#
|
577
|
+
# @example
|
578
|
+
# Polars::Series.new([true, true]).all?
|
579
|
+
# # => true
|
580
|
+
#
|
581
|
+
# @example
|
582
|
+
# Polars::Series.new([false, true]).all?
|
583
|
+
# # => false
|
584
|
+
#
|
585
|
+
# @example
|
586
|
+
# Polars::Series.new([nil, true]).all?
|
587
|
+
# # => true
|
546
588
|
def all?(ignore_nulls: true, &block)
|
547
589
|
if block_given?
|
548
590
|
apply(skip_nulls: ignore_nulls, &block).all?
|
@@ -555,6 +597,18 @@ module Polars
|
|
555
597
|
# Check if all boolean values in the column are `false`.
|
556
598
|
#
|
557
599
|
# @return [Boolean]
|
600
|
+
#
|
601
|
+
# @example
|
602
|
+
# Polars::Series.new([true, false]).none?
|
603
|
+
# # => false
|
604
|
+
#
|
605
|
+
# @example
|
606
|
+
# Polars::Series.new([false, false]).none?
|
607
|
+
# # => true
|
608
|
+
#
|
609
|
+
# @example
|
610
|
+
# Polars::Series.new([nil, false]).none?
|
611
|
+
# # => true
|
558
612
|
def none?(&block)
|
559
613
|
if block_given?
|
560
614
|
apply(&block).none?
|
@@ -570,6 +624,18 @@ module Polars
|
|
570
624
|
# Given base, defaults to `Math::E`.
|
571
625
|
#
|
572
626
|
# @return [Series]
|
627
|
+
#
|
628
|
+
# @example
|
629
|
+
# s = Polars::Series.new([1, 2, 3])
|
630
|
+
# s.log
|
631
|
+
# # =>
|
632
|
+
# # shape: (3,)
|
633
|
+
# # Series: '' [f64]
|
634
|
+
# # [
|
635
|
+
# # 0.0
|
636
|
+
# # 0.693147
|
637
|
+
# # 1.098612
|
638
|
+
# # ]
|
573
639
|
def log(base = Math::E)
|
574
640
|
super
|
575
641
|
end
|
@@ -577,6 +643,18 @@ module Polars
|
|
577
643
|
# Compute the base 10 logarithm of the input array, element-wise.
|
578
644
|
#
|
579
645
|
# @return [Series]
|
646
|
+
#
|
647
|
+
# @example
|
648
|
+
# s = Polars::Series.new([10, 100, 1000])
|
649
|
+
# s.log10
|
650
|
+
# # =>
|
651
|
+
# # shape: (3,)
|
652
|
+
# # Series: '' [f64]
|
653
|
+
# # [
|
654
|
+
# # 1.0
|
655
|
+
# # 2.0
|
656
|
+
# # 3.0
|
657
|
+
# # ]
|
580
658
|
def log10
|
581
659
|
super
|
582
660
|
end
|
@@ -584,6 +662,18 @@ module Polars
|
|
584
662
|
# Compute the exponential, element-wise.
|
585
663
|
#
|
586
664
|
# @return [Series]
|
665
|
+
#
|
666
|
+
# @example
|
667
|
+
# s = Polars::Series.new([1, 2, 3])
|
668
|
+
# s.exp
|
669
|
+
# # =>
|
670
|
+
# # shape: (3,)
|
671
|
+
# # Series: '' [f64]
|
672
|
+
# # [
|
673
|
+
# # 2.718282
|
674
|
+
# # 7.389056
|
675
|
+
# # 20.085537
|
676
|
+
# # ]
|
587
677
|
def exp
|
588
678
|
super
|
589
679
|
end
|
@@ -591,6 +681,18 @@ module Polars
|
|
591
681
|
# Create a new Series that copies data from this Series without null values.
|
592
682
|
#
|
593
683
|
# @return [Series]
|
684
|
+
#
|
685
|
+
# @example
|
686
|
+
# s = Polars::Series.new([1.0, nil, 3.0, Float::NAN])
|
687
|
+
# s.drop_nulls
|
688
|
+
# # =>
|
689
|
+
# # shape: (3,)
|
690
|
+
# # Series: '' [f64]
|
691
|
+
# # [
|
692
|
+
# # 1.0
|
693
|
+
# # 3.0
|
694
|
+
# # NaN
|
695
|
+
# # ]
|
594
696
|
def drop_nulls
|
595
697
|
super
|
596
698
|
end
|
@@ -598,6 +700,18 @@ module Polars
|
|
598
700
|
# Drop NaN values.
|
599
701
|
#
|
600
702
|
# @return [Series]
|
703
|
+
#
|
704
|
+
# @example
|
705
|
+
# s = Polars::Series.new([1.0, nil, 3.0, Float::NAN])
|
706
|
+
# s.drop_nans
|
707
|
+
# # =>
|
708
|
+
# # shape: (3,)
|
709
|
+
# # Series: '' [f64]
|
710
|
+
# # [
|
711
|
+
# # 1.0
|
712
|
+
# # null
|
713
|
+
# # 3.0
|
714
|
+
# # ]
|
601
715
|
def drop_nans
|
602
716
|
super
|
603
717
|
end
|
@@ -605,7 +719,37 @@ module Polars
|
|
605
719
|
# Cast this Series to a DataFrame.
|
606
720
|
#
|
607
721
|
# @return [DataFrame]
|
608
|
-
|
722
|
+
#
|
723
|
+
# @example
|
724
|
+
# s = Polars::Series.new("a", [123, 456])
|
725
|
+
# s.to_frame
|
726
|
+
# # =>
|
727
|
+
# # shape: (2, 1)
|
728
|
+
# # ┌─────┐
|
729
|
+
# # │ a │
|
730
|
+
# # │ --- │
|
731
|
+
# # │ i64 │
|
732
|
+
# # ╞═════╡
|
733
|
+
# # │ 123 │
|
734
|
+
# # │ 456 │
|
735
|
+
# # └─────┘
|
736
|
+
#
|
737
|
+
# @example
|
738
|
+
# s.to_frame("xyz")
|
739
|
+
# # =>
|
740
|
+
# # shape: (2, 1)
|
741
|
+
# # ┌─────┐
|
742
|
+
# # │ xyz │
|
743
|
+
# # │ --- │
|
744
|
+
# # │ i64 │
|
745
|
+
# # ╞═════╡
|
746
|
+
# # │ 123 │
|
747
|
+
# # │ 456 │
|
748
|
+
# # └─────┘
|
749
|
+
def to_frame(name = nil)
|
750
|
+
if name
|
751
|
+
return Utils.wrap_df(RbDataFrame.new([rename(name)._s]))
|
752
|
+
end
|
609
753
|
Utils.wrap_df(RbDataFrame.new([_s]))
|
610
754
|
end
|
611
755
|
|
@@ -722,6 +866,11 @@ module Polars
|
|
722
866
|
# Reduce this Series to the product value.
|
723
867
|
#
|
724
868
|
# @return [Numeric]
|
869
|
+
#
|
870
|
+
# @example
|
871
|
+
# s = Polars::Series.new("a", [1, 2, 3])
|
872
|
+
# s.product
|
873
|
+
# # => 6
|
725
874
|
def product
|
726
875
|
to_frame.select(Polars.col(name).product).to_series[0]
|
727
876
|
end
|
@@ -753,15 +902,35 @@ module Polars
|
|
753
902
|
# Get maximum value, but propagate/poison encountered NaN values.
|
754
903
|
#
|
755
904
|
# @return [Object]
|
905
|
+
#
|
906
|
+
# @example
|
907
|
+
# s = Polars::Series.new("a", [1, 3, 4])
|
908
|
+
# s.nan_max
|
909
|
+
# # => 4
|
910
|
+
#
|
911
|
+
# @example
|
912
|
+
# s = Polars::Series.new("a", [1.0, Float::NAN, 4.0])
|
913
|
+
# s.nan_max
|
914
|
+
# # => NaN
|
756
915
|
def nan_max
|
757
|
-
to_frame.select(
|
916
|
+
to_frame.select(F.col(name).nan_max)[0, 0]
|
758
917
|
end
|
759
918
|
|
760
919
|
# Get minimum value, but propagate/poison encountered NaN values.
|
761
920
|
#
|
762
921
|
# @return [Object]
|
922
|
+
#
|
923
|
+
# @example
|
924
|
+
# s = Polars::Series.new("a", [1, 3, 4])
|
925
|
+
# s.nan_min
|
926
|
+
# # => 1
|
927
|
+
#
|
928
|
+
# @example
|
929
|
+
# s = Polars::Series.new("a", [1.0, Float::NAN, 4.0])
|
930
|
+
# s.nan_min
|
931
|
+
# # => NaN
|
763
932
|
def nan_min
|
764
|
-
to_frame.select(
|
933
|
+
to_frame.select(F.col(name).nan_min)[0, 0]
|
765
934
|
end
|
766
935
|
|
767
936
|
# Get the standard deviation of this Series.
|
@@ -1661,20 +1830,7 @@ module Polars
|
|
1661
1830
|
def arg_sort(reverse: false, nulls_last: false)
|
1662
1831
|
super
|
1663
1832
|
end
|
1664
|
-
|
1665
|
-
# Get the index values that would sort this Series.
|
1666
|
-
#
|
1667
|
-
# Alias for {#arg_sort}.
|
1668
|
-
#
|
1669
|
-
# @param reverse [Boolean]
|
1670
|
-
# Sort in reverse (descending) order.
|
1671
|
-
# @param nulls_last [Boolean]
|
1672
|
-
# Place null values last instead of first.
|
1673
|
-
#
|
1674
|
-
# @return [Series]
|
1675
|
-
def argsort(reverse: false, nulls_last: false)
|
1676
|
-
super
|
1677
|
-
end
|
1833
|
+
alias_method :argsort, :arg_sort
|
1678
1834
|
|
1679
1835
|
# Get unique index as Series.
|
1680
1836
|
#
|
@@ -1725,6 +1881,52 @@ module Polars
|
|
1725
1881
|
# Expression or scalar value.
|
1726
1882
|
#
|
1727
1883
|
# @return [Integer]
|
1884
|
+
#
|
1885
|
+
# @example
|
1886
|
+
# s = Polars::Series.new("set", [1, 2, 3, 4, 4, 5, 6, 7])
|
1887
|
+
# s.search_sorted(4)
|
1888
|
+
# # => 3
|
1889
|
+
#
|
1890
|
+
# @example
|
1891
|
+
# s.search_sorted(4, side: "left")
|
1892
|
+
# # => 3
|
1893
|
+
#
|
1894
|
+
# @example
|
1895
|
+
# s.search_sorted(4, side: "right")
|
1896
|
+
# # => 5
|
1897
|
+
#
|
1898
|
+
# @example
|
1899
|
+
# s.search_sorted([1, 4, 5])
|
1900
|
+
# # =>
|
1901
|
+
# # shape: (3,)
|
1902
|
+
# # Series: 'set' [u32]
|
1903
|
+
# # [
|
1904
|
+
# # 0
|
1905
|
+
# # 3
|
1906
|
+
# # 5
|
1907
|
+
# # ]
|
1908
|
+
#
|
1909
|
+
# @example
|
1910
|
+
# s.search_sorted([1, 4, 5], side: "left")
|
1911
|
+
# # =>
|
1912
|
+
# # shape: (3,)
|
1913
|
+
# # Series: 'set' [u32]
|
1914
|
+
# # [
|
1915
|
+
# # 0
|
1916
|
+
# # 3
|
1917
|
+
# # 5
|
1918
|
+
# # ]
|
1919
|
+
#
|
1920
|
+
# @example
|
1921
|
+
# s.search_sorted([1, 4, 5], side: "right")
|
1922
|
+
# # =>
|
1923
|
+
# # shape: (3,)
|
1924
|
+
# # Series: 'set' [u32]
|
1925
|
+
# # [
|
1926
|
+
# # 1
|
1927
|
+
# # 5
|
1928
|
+
# # 6
|
1929
|
+
# # ]
|
1728
1930
|
def search_sorted(element, side: "any")
|
1729
1931
|
if element.is_a?(Integer) || element.is_a?(Float)
|
1730
1932
|
return Polars.select(Polars.lit(self).search_sorted(element, side: side)).item
|
@@ -1780,6 +1982,11 @@ module Polars
|
|
1780
1982
|
# Count the null values in this Series.
|
1781
1983
|
#
|
1782
1984
|
# @return [Integer]
|
1985
|
+
#
|
1986
|
+
# @example
|
1987
|
+
# s = Polars::Series.new([1, nil, nil])
|
1988
|
+
# s.null_count
|
1989
|
+
# # => 2
|
1783
1990
|
def null_count
|
1784
1991
|
_s.null_count
|
1785
1992
|
end
|
@@ -1790,6 +1997,15 @@ module Polars
|
|
1790
1997
|
# Use this to swiftly assert a Series does not have null values.
|
1791
1998
|
#
|
1792
1999
|
# @return [Boolean]
|
2000
|
+
#
|
2001
|
+
# @example
|
2002
|
+
# s = Polars::Series.new([1, 2, nil])
|
2003
|
+
# s.has_nulls
|
2004
|
+
# # => true
|
2005
|
+
#
|
2006
|
+
# @example
|
2007
|
+
# s[...2].has_nulls
|
2008
|
+
# # => false
|
1793
2009
|
def has_nulls
|
1794
2010
|
_s.has_nulls
|
1795
2011
|
end
|
@@ -2019,9 +2235,24 @@ module Polars
|
|
2019
2235
|
# Get a mask of the first unique value.
|
2020
2236
|
#
|
2021
2237
|
# @return [Series]
|
2022
|
-
|
2238
|
+
#
|
2239
|
+
# @example
|
2240
|
+
# s = Polars::Series.new([1, 1, 2, 3, 2])
|
2241
|
+
# s.is_first_distinct
|
2242
|
+
# # =>
|
2243
|
+
# # shape: (5,)
|
2244
|
+
# # Series: '' [bool]
|
2245
|
+
# # [
|
2246
|
+
# # true
|
2247
|
+
# # false
|
2248
|
+
# # true
|
2249
|
+
# # true
|
2250
|
+
# # false
|
2251
|
+
# # ]
|
2252
|
+
def is_first_distinct
|
2023
2253
|
super
|
2024
2254
|
end
|
2255
|
+
alias_method :is_first, :is_first_distinct
|
2025
2256
|
|
2026
2257
|
# Get mask of all duplicated values.
|
2027
2258
|
#
|
@@ -2187,6 +2418,35 @@ module Polars
|
|
2187
2418
|
# In place or not.
|
2188
2419
|
#
|
2189
2420
|
# @return [Series]
|
2421
|
+
#
|
2422
|
+
# @example
|
2423
|
+
# s1 = Polars::Series.new("a", [1, 2, 3])
|
2424
|
+
# s1.n_chunks
|
2425
|
+
# # => 1
|
2426
|
+
#
|
2427
|
+
# @example
|
2428
|
+
# s2 = Polars::Series.new("a", [4, 5, 6])
|
2429
|
+
# s = Polars.concat([s1, s2], rechunk: false)
|
2430
|
+
# s.n_chunks
|
2431
|
+
# # => 2
|
2432
|
+
#
|
2433
|
+
# @example
|
2434
|
+
# s.rechunk(in_place: true)
|
2435
|
+
# # =>
|
2436
|
+
# # shape: (6,)
|
2437
|
+
# # Series: 'a' [i64]
|
2438
|
+
# # [
|
2439
|
+
# # 1
|
2440
|
+
# # 2
|
2441
|
+
# # 3
|
2442
|
+
# # 4
|
2443
|
+
# # 5
|
2444
|
+
# # 6
|
2445
|
+
# # ]
|
2446
|
+
#
|
2447
|
+
# @example
|
2448
|
+
# s.n_chunks
|
2449
|
+
# # => 1
|
2190
2450
|
def rechunk(in_place: false)
|
2191
2451
|
opt_s = _s.rechunk(in_place)
|
2192
2452
|
in_place ? self : Utils.wrap_s(opt_s)
|
@@ -2606,12 +2866,12 @@ module Polars
|
|
2606
2866
|
# s.sign
|
2607
2867
|
# # =>
|
2608
2868
|
# # shape: (5,)
|
2609
|
-
# # Series: 'a' [
|
2869
|
+
# # Series: 'a' [f64]
|
2610
2870
|
# # [
|
2611
|
-
# # -1
|
2612
|
-
# # 0
|
2613
|
-
# # 0
|
2614
|
-
# # 1
|
2871
|
+
# # -1.0
|
2872
|
+
# # -0.0
|
2873
|
+
# # 0.0
|
2874
|
+
# # 1.0
|
2615
2875
|
# # null
|
2616
2876
|
# # ]
|
2617
2877
|
def sign
|
@@ -3518,6 +3778,18 @@ module Polars
|
|
3518
3778
|
# If true, reinterpret as `:i64`. Otherwise, reinterpret as `:u64`.
|
3519
3779
|
#
|
3520
3780
|
# @return [Series]
|
3781
|
+
#
|
3782
|
+
# @example
|
3783
|
+
# s = Polars::Series.new("a", [-(2**60), -2, 3])
|
3784
|
+
# s.reinterpret(signed: false)
|
3785
|
+
# # =>
|
3786
|
+
# # shape: (3,)
|
3787
|
+
# # Series: 'a' [u64]
|
3788
|
+
# # [
|
3789
|
+
# # 17293822569102704640
|
3790
|
+
# # 18446744073709551614
|
3791
|
+
# # 3
|
3792
|
+
# # ]
|
3521
3793
|
def reinterpret(signed: true)
|
3522
3794
|
super
|
3523
3795
|
end
|
@@ -3546,6 +3818,18 @@ module Polars
|
|
3546
3818
|
# Compute absolute values.
|
3547
3819
|
#
|
3548
3820
|
# @return [Series]
|
3821
|
+
#
|
3822
|
+
# @example
|
3823
|
+
# s = Polars::Series.new([1, -2, -3])
|
3824
|
+
# s.abs
|
3825
|
+
# # =>
|
3826
|
+
# # shape: (3,)
|
3827
|
+
# # Series: '' [i64]
|
3828
|
+
# # [
|
3829
|
+
# # 1
|
3830
|
+
# # 2
|
3831
|
+
# # 3
|
3832
|
+
# # ]
|
3549
3833
|
def abs
|
3550
3834
|
super
|
3551
3835
|
end
|
@@ -3616,6 +3900,44 @@ module Polars
|
|
3616
3900
|
# How to handle null values.
|
3617
3901
|
#
|
3618
3902
|
# @return [Series]
|
3903
|
+
#
|
3904
|
+
# @example
|
3905
|
+
# s = Polars::Series.new("s", [20, 10, 30, 25, 35], dtype: Polars::Int8)
|
3906
|
+
# s.diff
|
3907
|
+
# # =>
|
3908
|
+
# # shape: (5,)
|
3909
|
+
# # Series: 's' [i8]
|
3910
|
+
# # [
|
3911
|
+
# # null
|
3912
|
+
# # -10
|
3913
|
+
# # 20
|
3914
|
+
# # -5
|
3915
|
+
# # 10
|
3916
|
+
# # ]
|
3917
|
+
#
|
3918
|
+
# @example
|
3919
|
+
# s.diff(n: 2)
|
3920
|
+
# # =>
|
3921
|
+
# # shape: (5,)
|
3922
|
+
# # Series: 's' [i8]
|
3923
|
+
# # [
|
3924
|
+
# # null
|
3925
|
+
# # null
|
3926
|
+
# # 10
|
3927
|
+
# # 15
|
3928
|
+
# # 5
|
3929
|
+
# # ]
|
3930
|
+
#
|
3931
|
+
# @example
|
3932
|
+
# s.diff(n: 2, null_behavior: "drop")
|
3933
|
+
# # =>
|
3934
|
+
# # shape: (3,)
|
3935
|
+
# # Series: 's' [i8]
|
3936
|
+
# # [
|
3937
|
+
# # 10
|
3938
|
+
# # 15
|
3939
|
+
# # 5
|
3940
|
+
# # ]
|
3619
3941
|
def diff(n: 1, null_behavior: "ignore")
|
3620
3942
|
super
|
3621
3943
|
end
|
@@ -3683,6 +4005,11 @@ module Polars
|
|
3683
4005
|
# If `false`, the calculations are corrected for statistical bias.
|
3684
4006
|
#
|
3685
4007
|
# @return [Float, nil]
|
4008
|
+
#
|
4009
|
+
# @example
|
4010
|
+
# s = Polars::Series.new([1, 2, 2, 4, 5])
|
4011
|
+
# s.skew
|
4012
|
+
# # => 0.34776706224699483
|
3686
4013
|
def skew(bias: true)
|
3687
4014
|
_s.skew(bias)
|
3688
4015
|
end
|
@@ -3702,6 +4029,19 @@ module Polars
|
|
3702
4029
|
# If `false`, the calculations are corrected for statistical bias.
|
3703
4030
|
#
|
3704
4031
|
# @return [Float, nil]
|
4032
|
+
#
|
4033
|
+
# @example
|
4034
|
+
# s = Polars::Series.new("grades", [66, 79, 54, 97, 96, 70, 69, 85, 93, 75])
|
4035
|
+
# s.kurtosis
|
4036
|
+
# # => -1.0522623626787952
|
4037
|
+
#
|
4038
|
+
# @example
|
4039
|
+
# s.kurtosis(fisher: false)
|
4040
|
+
# # => 1.9477376373212048
|
4041
|
+
#
|
4042
|
+
# @example
|
4043
|
+
# s.kurtosis(fisher: false, bias: false)
|
4044
|
+
# # => 2.1040361802642726
|
3705
4045
|
def kurtosis(fisher: true, bias: true)
|
3706
4046
|
_s.kurtosis(fisher, bias)
|
3707
4047
|
end
|
@@ -3845,6 +4185,35 @@ module Polars
|
|
3845
4185
|
# dimension is inferred.
|
3846
4186
|
#
|
3847
4187
|
# @return [Series]
|
4188
|
+
#
|
4189
|
+
# @example
|
4190
|
+
# s = Polars::Series.new("foo", [1, 2, 3, 4, 5, 6, 7, 8, 9])
|
4191
|
+
# square = s.reshape([3, 3])
|
4192
|
+
# # =>
|
4193
|
+
# # shape: (3,)
|
4194
|
+
# # Series: 'foo' [array[i64, 3]]
|
4195
|
+
# # [
|
4196
|
+
# # [1, 2, 3]
|
4197
|
+
# # [4, 5, 6]
|
4198
|
+
# # [7, 8, 9]
|
4199
|
+
# # ]
|
4200
|
+
#
|
4201
|
+
# @example
|
4202
|
+
# square.reshape([9])
|
4203
|
+
# # =>
|
4204
|
+
# # shape: (9,)
|
4205
|
+
# # Series: 'foo' [i64]
|
4206
|
+
# # [
|
4207
|
+
# # 1
|
4208
|
+
# # 2
|
4209
|
+
# # 3
|
4210
|
+
# # 4
|
4211
|
+
# # 5
|
4212
|
+
# # 6
|
4213
|
+
# # 7
|
4214
|
+
# # 8
|
4215
|
+
# # 9
|
4216
|
+
# # ]
|
3848
4217
|
def reshape(dims)
|
3849
4218
|
super
|
3850
4219
|
end
|
@@ -3874,6 +4243,18 @@ module Polars
|
|
3874
4243
|
# Exponentially-weighted moving average.
|
3875
4244
|
#
|
3876
4245
|
# @return [Series]
|
4246
|
+
#
|
4247
|
+
# @example
|
4248
|
+
# s = Polars::Series.new([1, 2, 3])
|
4249
|
+
# s.ewm_mean(com: 1, ignore_nulls: false)
|
4250
|
+
# # =>
|
4251
|
+
# # shape: (3,)
|
4252
|
+
# # Series: '' [f64]
|
4253
|
+
# # [
|
4254
|
+
# # 1.0
|
4255
|
+
# # 1.666667
|
4256
|
+
# # 2.428571
|
4257
|
+
# # ]
|
3877
4258
|
def ewm_mean(
|
3878
4259
|
com: nil,
|
3879
4260
|
span: nil,
|
@@ -3889,6 +4270,18 @@ module Polars
|
|
3889
4270
|
# Exponentially-weighted moving standard deviation.
|
3890
4271
|
#
|
3891
4272
|
# @return [Series]
|
4273
|
+
#
|
4274
|
+
# @example
|
4275
|
+
# s = Polars::Series.new("a", [1, 2, 3])
|
4276
|
+
# s.ewm_std(com: 1, ignore_nulls: false)
|
4277
|
+
# # =>
|
4278
|
+
# # shape: (3,)
|
4279
|
+
# # Series: 'a' [f64]
|
4280
|
+
# # [
|
4281
|
+
# # 0.0
|
4282
|
+
# # 0.707107
|
4283
|
+
# # 0.963624
|
4284
|
+
# # ]
|
3892
4285
|
def ewm_std(
|
3893
4286
|
com: nil,
|
3894
4287
|
span: nil,
|
@@ -3905,6 +4298,18 @@ module Polars
|
|
3905
4298
|
# Exponentially-weighted moving variance.
|
3906
4299
|
#
|
3907
4300
|
# @return [Series]
|
4301
|
+
#
|
4302
|
+
# @example
|
4303
|
+
# s = Polars::Series.new("a", [1, 2, 3])
|
4304
|
+
# s.ewm_var(com: 1, ignore_nulls: false)
|
4305
|
+
# # =>
|
4306
|
+
# # shape: (3,)
|
4307
|
+
# # Series: 'a' [f64]
|
4308
|
+
# # [
|
4309
|
+
# # 0.0
|
4310
|
+
# # 0.5
|
4311
|
+
# # 0.928571
|
4312
|
+
# # ]
|
3908
4313
|
def ewm_var(
|
3909
4314
|
com: nil,
|
3910
4315
|
span: nil,
|
@@ -3969,6 +4374,18 @@ module Polars
|
|
3969
4374
|
# Create a new Series filled with values from the given index.
|
3970
4375
|
#
|
3971
4376
|
# @return [Series]
|
4377
|
+
#
|
4378
|
+
# @example
|
4379
|
+
# s = Polars::Series.new("a", [1, 2, 3, 4, 5])
|
4380
|
+
# s.new_from_index(1, 3)
|
4381
|
+
# # =>
|
4382
|
+
# # shape: (3,)
|
4383
|
+
# # Series: 'a' [i64]
|
4384
|
+
# # [
|
4385
|
+
# # 2
|
4386
|
+
# # 2
|
4387
|
+
# # 2
|
4388
|
+
# # ]
|
3972
4389
|
def new_from_index(index, length)
|
3973
4390
|
Utils.wrap_s(_s.new_from_index(index, length))
|
3974
4391
|
end
|
@@ -3979,6 +4396,21 @@ module Polars
|
|
3979
4396
|
# This can be used to reduce memory pressure.
|
3980
4397
|
#
|
3981
4398
|
# @return [Series]
|
4399
|
+
#
|
4400
|
+
# @example
|
4401
|
+
# s = Polars::Series.new("a", [1, 2, 3, 4, 5, 6])
|
4402
|
+
# s.shrink_dtype
|
4403
|
+
# # =>
|
4404
|
+
# # shape: (6,)
|
4405
|
+
# # Series: 'a' [i8]
|
4406
|
+
# # [
|
4407
|
+
# # 1
|
4408
|
+
# # 2
|
4409
|
+
# # 3
|
4410
|
+
# # 4
|
4411
|
+
# # 5
|
4412
|
+
# # 6
|
4413
|
+
# # ]
|
3982
4414
|
def shrink_dtype
|
3983
4415
|
super
|
3984
4416
|
end
|
@@ -4264,12 +4696,10 @@ module Polars
|
|
4264
4696
|
end
|
4265
4697
|
|
4266
4698
|
constructor = polars_type_to_constructor(dtype)
|
4267
|
-
# TODO remove
|
4268
|
-
strict = false if dtype == Decimal
|
4269
4699
|
rbseries = constructor.call(name, values, strict)
|
4270
4700
|
|
4271
4701
|
base_type = dtype.is_a?(DataType) ? dtype.class : dtype
|
4272
|
-
if [Date, Datetime, Duration, Time, Categorical, Boolean, Enum].include?(base_type)
|
4702
|
+
if [Date, Datetime, Duration, Time, Categorical, Boolean, Enum, Decimal].include?(base_type)
|
4273
4703
|
if rbseries.dtype != dtype
|
4274
4704
|
rbseries = rbseries.cast(dtype, true)
|
4275
4705
|
end
|