polars-df 0.2.1-x86_64-darwin → 0.2.2-x86_64-darwin
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/Cargo.lock +1 -1
- data/LICENSE-THIRD-PARTY.txt +80 -80
- data/README.md +6 -3
- data/lib/polars/3.0/polars.bundle +0 -0
- data/lib/polars/3.1/polars.bundle +0 -0
- data/lib/polars/3.2/polars.bundle +0 -0
- data/lib/polars/data_frame.rb +66 -3
- data/lib/polars/io.rb +3 -1
- data/lib/polars/series.rb +71 -11
- data/lib/polars/slice.rb +1 -1
- data/lib/polars/utils.rb +20 -0
- data/lib/polars/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f2791c0d21e29dda330d14874b48d97476fa978a59ea032cef261b1a1bf7ed1
|
4
|
+
data.tar.gz: 0f1cf1de038b52be6bdd7fe17edec67c30640026dc77c1c63788ffa9f226cb7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b3af7d10ceadd9bc4f4d0d0d286efb5b2002a1bd02ba1004ce0ed616ded94971dfc08dc7ba00db885c90fdef948e3fa034f8735d6ff68bd253a10355200fc65
|
7
|
+
data.tar.gz: 22a67553be610272d81dace623a8035c45da63bb8c05b866c636a581921a70f1ff0bef84a1d84aa65c4c9d6ed50fc4d31f214aab5221dd1becef8aec6a5a2e68
|
data/CHANGELOG.md
CHANGED
data/Cargo.lock
CHANGED
data/LICENSE-THIRD-PARTY.txt
CHANGED
@@ -1640,6 +1640,33 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
1640
1640
|
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
1641
1641
|
DEALINGS IN THE SOFTWARE.
|
1642
1642
|
|
1643
|
+
================================================================================
|
1644
|
+
array-init-cursor LICENSE-MIT
|
1645
|
+
================================================================================
|
1646
|
+
|
1647
|
+
MIT License
|
1648
|
+
|
1649
|
+
Copyright (c) 2021 The Planus Project Developers
|
1650
|
+
|
1651
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
1652
|
+
of this software and associated documentation files (the "Software"), to deal
|
1653
|
+
in the Software without restriction, including without limitation the rights
|
1654
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
1655
|
+
copies of the Software, and to permit persons to whom the Software is
|
1656
|
+
furnished to do so, subject to the following conditions:
|
1657
|
+
|
1658
|
+
The above copyright notice and this permission notice shall be included in all
|
1659
|
+
copies or substantial portions of the Software.
|
1660
|
+
|
1661
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
1662
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
1663
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
1664
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
1665
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
1666
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
1667
|
+
SOFTWARE.
|
1668
|
+
|
1669
|
+
|
1643
1670
|
================================================================================
|
1644
1671
|
array-init-cursor LICENSE-APACHE
|
1645
1672
|
================================================================================
|
@@ -1822,33 +1849,6 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
1822
1849
|
END OF TERMS AND CONDITIONS
|
1823
1850
|
|
1824
1851
|
|
1825
|
-
================================================================================
|
1826
|
-
array-init-cursor LICENSE-MIT
|
1827
|
-
================================================================================
|
1828
|
-
|
1829
|
-
MIT License
|
1830
|
-
|
1831
|
-
Copyright (c) 2021 The Planus Project Developers
|
1832
|
-
|
1833
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
1834
|
-
of this software and associated documentation files (the "Software"), to deal
|
1835
|
-
in the Software without restriction, including without limitation the rights
|
1836
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
1837
|
-
copies of the Software, and to permit persons to whom the Software is
|
1838
|
-
furnished to do so, subject to the following conditions:
|
1839
|
-
|
1840
|
-
The above copyright notice and this permission notice shall be included in all
|
1841
|
-
copies or substantial portions of the Software.
|
1842
|
-
|
1843
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
1844
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
1845
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
1846
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
1847
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
1848
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
1849
|
-
SOFTWARE.
|
1850
|
-
|
1851
|
-
|
1852
1852
|
================================================================================
|
1853
1853
|
arrow-format LICENSE
|
1854
1854
|
================================================================================
|
@@ -27103,6 +27103,33 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
27103
27103
|
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
27104
27104
|
DEALINGS IN THE SOFTWARE.
|
27105
27105
|
|
27106
|
+
================================================================================
|
27107
|
+
planus LICENSE-MIT
|
27108
|
+
================================================================================
|
27109
|
+
|
27110
|
+
MIT License
|
27111
|
+
|
27112
|
+
Copyright (c) 2021 The Planus Project Developers
|
27113
|
+
|
27114
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
27115
|
+
of this software and associated documentation files (the "Software"), to deal
|
27116
|
+
in the Software without restriction, including without limitation the rights
|
27117
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
27118
|
+
copies of the Software, and to permit persons to whom the Software is
|
27119
|
+
furnished to do so, subject to the following conditions:
|
27120
|
+
|
27121
|
+
The above copyright notice and this permission notice shall be included in all
|
27122
|
+
copies or substantial portions of the Software.
|
27123
|
+
|
27124
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
27125
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
27126
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
27127
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27128
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
27129
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
27130
|
+
SOFTWARE.
|
27131
|
+
|
27132
|
+
|
27106
27133
|
================================================================================
|
27107
27134
|
planus LICENSE-APACHE
|
27108
27135
|
================================================================================
|
@@ -27285,33 +27312,6 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
27285
27312
|
END OF TERMS AND CONDITIONS
|
27286
27313
|
|
27287
27314
|
|
27288
|
-
================================================================================
|
27289
|
-
planus LICENSE-MIT
|
27290
|
-
================================================================================
|
27291
|
-
|
27292
|
-
MIT License
|
27293
|
-
|
27294
|
-
Copyright (c) 2021 The Planus Project Developers
|
27295
|
-
|
27296
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
27297
|
-
of this software and associated documentation files (the "Software"), to deal
|
27298
|
-
in the Software without restriction, including without limitation the rights
|
27299
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
27300
|
-
copies of the Software, and to permit persons to whom the Software is
|
27301
|
-
furnished to do so, subject to the following conditions:
|
27302
|
-
|
27303
|
-
The above copyright notice and this permission notice shall be included in all
|
27304
|
-
copies or substantial portions of the Software.
|
27305
|
-
|
27306
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
27307
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
27308
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
27309
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27310
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
27311
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
27312
|
-
SOFTWARE.
|
27313
|
-
|
27314
|
-
|
27315
27315
|
================================================================================
|
27316
27316
|
polars LICENSE
|
27317
27317
|
================================================================================
|
@@ -30064,6 +30064,32 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30064
30064
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
30065
30065
|
SOFTWARE.
|
30066
30066
|
|
30067
|
+
================================================================================
|
30068
|
+
rb-sys-env LICENSE-MIT
|
30069
|
+
================================================================================
|
30070
|
+
|
30071
|
+
The MIT License (MIT)
|
30072
|
+
|
30073
|
+
Copyright (c) 2021-2022 Ian Ker-Seymer
|
30074
|
+
|
30075
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
30076
|
+
of this software and associated documentation files (the "Software"), to deal
|
30077
|
+
in the Software without restriction, including without limitation the rights
|
30078
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
30079
|
+
copies of the Software, and to permit persons to whom the Software is
|
30080
|
+
furnished to do so, subject to the following conditions:
|
30081
|
+
|
30082
|
+
The above copyright notice and this permission notice shall be included in all
|
30083
|
+
copies or substantial portions of the Software.
|
30084
|
+
|
30085
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
30086
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
30087
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
30088
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
30089
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
30090
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
30091
|
+
SOFTWARE.
|
30092
|
+
|
30067
30093
|
================================================================================
|
30068
30094
|
rb-sys-env LICENSE-APACHE
|
30069
30095
|
================================================================================
|
@@ -30259,32 +30285,6 @@ rb-sys-env LICENSE-APACHE
|
|
30259
30285
|
See the License for the specific language governing permissions and
|
30260
30286
|
limitations under the License.
|
30261
30287
|
|
30262
|
-
================================================================================
|
30263
|
-
rb-sys-env LICENSE-MIT
|
30264
|
-
================================================================================
|
30265
|
-
|
30266
|
-
The MIT License (MIT)
|
30267
|
-
|
30268
|
-
Copyright (c) 2021-2022 Ian Ker-Seymer
|
30269
|
-
|
30270
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
30271
|
-
of this software and associated documentation files (the "Software"), to deal
|
30272
|
-
in the Software without restriction, including without limitation the rights
|
30273
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
30274
|
-
copies of the Software, and to permit persons to whom the Software is
|
30275
|
-
furnished to do so, subject to the following conditions:
|
30276
|
-
|
30277
|
-
The above copyright notice and this permission notice shall be included in all
|
30278
|
-
copies or substantial portions of the Software.
|
30279
|
-
|
30280
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
30281
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
30282
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
30283
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
30284
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
30285
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
30286
|
-
SOFTWARE.
|
30287
|
-
|
30288
30288
|
================================================================================
|
30289
30289
|
regex LICENSE-APACHE
|
30290
30290
|
================================================================================
|
data/README.md
CHANGED
@@ -41,6 +41,9 @@ From a CSV
|
|
41
41
|
|
42
42
|
```ruby
|
43
43
|
Polars.read_csv("file.csv")
|
44
|
+
|
45
|
+
# or lazily with
|
46
|
+
Polars.scan_csv("file.csv")
|
44
47
|
```
|
45
48
|
|
46
49
|
From Parquet
|
@@ -135,9 +138,9 @@ df[Polars.col("a") <= 2]
|
|
135
138
|
And, or, and exclusive or
|
136
139
|
|
137
140
|
```ruby
|
138
|
-
df[(Polars.col("a") >
|
139
|
-
df[(Polars.col("a") >
|
140
|
-
df[(Polars.col("a") >
|
141
|
+
df[(Polars.col("a") > 1) & (Polars.col("b") == "two")] # and
|
142
|
+
df[(Polars.col("a") > 1) | (Polars.col("b") == "two")] # or
|
143
|
+
df[(Polars.col("a") > 1) ^ (Polars.col("b") == "two")] # xor
|
141
144
|
```
|
142
145
|
|
143
146
|
## Operations
|
Binary file
|
Binary file
|
Binary file
|
data/lib/polars/data_frame.rb
CHANGED
@@ -277,6 +277,7 @@ module Polars
|
|
277
277
|
_df.height
|
278
278
|
end
|
279
279
|
alias_method :count, :height
|
280
|
+
alias_method :length, :height
|
280
281
|
|
281
282
|
# Get the width of the DataFrame.
|
282
283
|
#
|
@@ -541,7 +542,7 @@ module Polars
|
|
541
542
|
|
542
543
|
if col_selection.is_a?(Array)
|
543
544
|
# df[.., [1, 2]]
|
544
|
-
if is_int_sequence(col_selection)
|
545
|
+
if Utils.is_int_sequence(col_selection)
|
545
546
|
series_list = col_selection.map { |i| to_series(i) }
|
546
547
|
df = self.class.new(series_list)
|
547
548
|
return df[row_selection]
|
@@ -574,6 +575,23 @@ module Polars
|
|
574
575
|
# df[["foo", "bar"]]
|
575
576
|
return _from_rbdf(_df.select(item))
|
576
577
|
end
|
578
|
+
|
579
|
+
if Utils.is_int_sequence(item)
|
580
|
+
item = Series.new("", item)
|
581
|
+
end
|
582
|
+
|
583
|
+
if item.is_a?(Series)
|
584
|
+
dtype = item.dtype
|
585
|
+
if dtype == Utf8
|
586
|
+
return _from_rbdf(_df.select(item))
|
587
|
+
elsif dtype == UInt32
|
588
|
+
return _from_rbdf(_df.take_with_series(item._s))
|
589
|
+
elsif [UInt8, UInt16, UInt64, Int8, Int16, Int32, Int64].include?(dtype)
|
590
|
+
return _from_rbdf(
|
591
|
+
_df.take_with_series(_pos_idxs(item, 0)._s)
|
592
|
+
)
|
593
|
+
end
|
594
|
+
end
|
577
595
|
end
|
578
596
|
|
579
597
|
# Ruby-specific
|
@@ -4662,8 +4680,53 @@ module Polars
|
|
4662
4680
|
end
|
4663
4681
|
end
|
4664
4682
|
|
4665
|
-
|
4666
|
-
|
4683
|
+
def _pos_idxs(idxs, dim)
|
4684
|
+
idx_type = Polars._get_idx_type
|
4685
|
+
|
4686
|
+
if idxs.is_a?(Series)
|
4687
|
+
if idxs.dtype == idx_type
|
4688
|
+
return idxs
|
4689
|
+
end
|
4690
|
+
if [UInt8, UInt16, idx_type == UInt32 ? UInt64 : UInt32, Int8, Int16, Int32, Int64].include?(idxs.dtype)
|
4691
|
+
if idx_type == UInt32
|
4692
|
+
if [Int64, UInt64].include?(idxs.dtype)
|
4693
|
+
if idxs.max >= 2**32
|
4694
|
+
raise ArgumentError, "Index positions should be smaller than 2^32."
|
4695
|
+
end
|
4696
|
+
end
|
4697
|
+
if idxs.dtype == Int64
|
4698
|
+
if idxs.min < -(2**32)
|
4699
|
+
raise ArgumentError, "Index positions should be bigger than -2^32 + 1."
|
4700
|
+
end
|
4701
|
+
end
|
4702
|
+
end
|
4703
|
+
if [Int8, Int16, Int32, Int64].include?(idxs.dtype)
|
4704
|
+
if idxs.min < 0
|
4705
|
+
if idx_type == UInt32
|
4706
|
+
if [Int8, Int16].include?(idxs.dtype)
|
4707
|
+
idxs = idxs.cast(Int32)
|
4708
|
+
end
|
4709
|
+
else
|
4710
|
+
if [Int8, Int16, Int32].include?(idxs.dtype)
|
4711
|
+
idxs = idxs.cast(Int64)
|
4712
|
+
end
|
4713
|
+
end
|
4714
|
+
|
4715
|
+
idxs =
|
4716
|
+
Polars.select(
|
4717
|
+
Polars.when(Polars.lit(idxs) < 0)
|
4718
|
+
.then(shape[dim] + Polars.lit(idxs))
|
4719
|
+
.otherwise(Polars.lit(idxs))
|
4720
|
+
).to_series
|
4721
|
+
end
|
4722
|
+
end
|
4723
|
+
|
4724
|
+
return idxs.cast(idx_type)
|
4725
|
+
end
|
4726
|
+
end
|
4727
|
+
|
4728
|
+
raise ArgumentError, "Unsupported idxs datatype."
|
4729
|
+
end
|
4667
4730
|
|
4668
4731
|
# @private
|
4669
4732
|
def self.hash_to_rbdf(data, columns: nil)
|
data/lib/polars/io.rb
CHANGED
@@ -606,8 +606,10 @@ module Polars
|
|
606
606
|
sql
|
607
607
|
elsif sql.is_a?(ActiveRecord::Relation)
|
608
608
|
sql.connection.select_all(sql.to_sql)
|
609
|
+
elsif sql.is_a?(String)
|
610
|
+
ActiveRecord::Base.connection.select_all(sql)
|
609
611
|
else
|
610
|
-
raise ArgumentError, "Expected ActiveRecord::Relation
|
612
|
+
raise ArgumentError, "Expected ActiveRecord::Relation, ActiveRecord::Result, or String"
|
611
613
|
end
|
612
614
|
data = {}
|
613
615
|
result.columns.each_with_index do |k, i|
|
data/lib/polars/series.rb
CHANGED
@@ -263,6 +263,10 @@ module Polars
|
|
263
263
|
#
|
264
264
|
# @return [Object]
|
265
265
|
def [](item)
|
266
|
+
if item.is_a?(Series) && [UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64].include?(item.dtype)
|
267
|
+
return Utils.wrap_s(_s.take_with_series(_pos_idxs(item)._s))
|
268
|
+
end
|
269
|
+
|
266
270
|
if item.is_a?(Integer)
|
267
271
|
return _s.get_idx(item)
|
268
272
|
end
|
@@ -271,6 +275,10 @@ module Polars
|
|
271
275
|
return Slice.new(self).apply(item)
|
272
276
|
end
|
273
277
|
|
278
|
+
if Utils.is_int_sequence(item)
|
279
|
+
return Utils.wrap_s(_s.take_with_series(_pos_idxs(Series.new("", item))._s))
|
280
|
+
end
|
281
|
+
|
274
282
|
raise ArgumentError, "Cannot get item of type: #{item.class.name}"
|
275
283
|
end
|
276
284
|
|
@@ -287,24 +295,23 @@ module Polars
|
|
287
295
|
end
|
288
296
|
|
289
297
|
if key.is_a?(Series)
|
290
|
-
if key.dtype ==
|
298
|
+
if key.dtype == Boolean
|
291
299
|
self._s = set(key, value)._s
|
292
|
-
elsif key.dtype ==
|
293
|
-
self._s = set_at_idx(key.cast(
|
294
|
-
elsif key.dtype ==
|
300
|
+
elsif key.dtype == UInt64
|
301
|
+
self._s = set_at_idx(key.cast(UInt32), value)._s
|
302
|
+
elsif key.dtype == UInt32
|
295
303
|
self._s = set_at_idx(key, value)._s
|
296
304
|
else
|
297
305
|
raise Todo
|
298
306
|
end
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
307
|
+
elsif key.is_a?(Array)
|
308
|
+
s = Utils.wrap_s(sequence_to_rbseries("", key, dtype: UInt32))
|
309
|
+
self[s] = value
|
310
|
+
elsif key.is_a?(Range)
|
311
|
+
s = Series.new("", key, dtype: UInt32)
|
303
312
|
self[s] = value
|
304
313
|
elsif key.is_a?(Integer)
|
305
|
-
|
306
|
-
# self[[key]] = value
|
307
|
-
set_at_idx(key, value)
|
314
|
+
self[[key]] = value
|
308
315
|
else
|
309
316
|
raise ArgumentError, "cannot use #{key} for indexing"
|
310
317
|
end
|
@@ -3527,6 +3534,59 @@ module Polars
|
|
3527
3534
|
end
|
3528
3535
|
end
|
3529
3536
|
|
3537
|
+
def _pos_idxs(idxs)
|
3538
|
+
idx_type = Polars._get_idx_type
|
3539
|
+
|
3540
|
+
if idxs.is_a?(Series)
|
3541
|
+
if idxs.dtype == idx_type
|
3542
|
+
return idxs
|
3543
|
+
end
|
3544
|
+
if [UInt8, UInt16, idx_type == UInt32 ? UInt64 : UInt32, Int8, Int16, Int32, Int64].include?(idxs.dtype)
|
3545
|
+
if idx_type == UInt32
|
3546
|
+
if [Int64, UInt64].include?(idxs.dtype)
|
3547
|
+
if idxs.max >= 2**32
|
3548
|
+
raise ArgumentError, "Index positions should be smaller than 2^32."
|
3549
|
+
end
|
3550
|
+
end
|
3551
|
+
if idxs.dtype == Int64
|
3552
|
+
if idxs.min < -(2**32)
|
3553
|
+
raise ArgumentError, "Index positions should be bigger than -2^32 + 1."
|
3554
|
+
end
|
3555
|
+
end
|
3556
|
+
end
|
3557
|
+
if [Int8, Int16, Int32, Int64].include?(idxs.dtype)
|
3558
|
+
if idxs.min < 0
|
3559
|
+
if idx_type == UInt32
|
3560
|
+
if [Int8, Int16].include?(idxs.dtype)
|
3561
|
+
idxs = idxs.cast(Int32)
|
3562
|
+
end
|
3563
|
+
else
|
3564
|
+
if [Int8, Int16, Int32].include?(idxs.dtype)
|
3565
|
+
idxs = idxs.cast(Int64)
|
3566
|
+
end
|
3567
|
+
end
|
3568
|
+
|
3569
|
+
# Update negative indexes to absolute indexes.
|
3570
|
+
return (
|
3571
|
+
idxs.to_frame
|
3572
|
+
.select(
|
3573
|
+
Polars.when(Polars.col(idxs.name) < 0)
|
3574
|
+
.then(len + Polars.col(idxs.name))
|
3575
|
+
.otherwise(Polars.col(idxs.name))
|
3576
|
+
.cast(idx_type)
|
3577
|
+
)
|
3578
|
+
.to_series(0)
|
3579
|
+
)
|
3580
|
+
end
|
3581
|
+
end
|
3582
|
+
|
3583
|
+
return idxs.cast(idx_type)
|
3584
|
+
end
|
3585
|
+
end
|
3586
|
+
|
3587
|
+
raise ArgumentError, "Unsupported idxs datatype."
|
3588
|
+
end
|
3589
|
+
|
3530
3590
|
def _comp(other, op)
|
3531
3591
|
if other.is_a?(Series)
|
3532
3592
|
return Utils.wrap_s(_s.send(op, other._s))
|
data/lib/polars/slice.rb
CHANGED
@@ -56,7 +56,7 @@ module Polars
|
|
56
56
|
# Normalize slice bounds, identify unbounded and/or zero-length slices.
|
57
57
|
def _slice_setup(s)
|
58
58
|
# can normalize slice indices as we know object size
|
59
|
-
obj_len = @obj.
|
59
|
+
obj_len = @obj.length
|
60
60
|
start = if s.begin
|
61
61
|
if s.begin < 0
|
62
62
|
[s.begin + obj_len, 0].max
|
data/lib/polars/utils.rb
CHANGED
@@ -181,6 +181,26 @@ module Polars
|
|
181
181
|
val.all? { |x| x.is_a?(eltype) }
|
182
182
|
end
|
183
183
|
|
184
|
+
def self.is_bool_sequence(val)
|
185
|
+
val.is_a?(Array) && val.all? { |x| x == true || x == false }
|
186
|
+
end
|
187
|
+
|
188
|
+
def self.is_dtype_sequence(val)
|
189
|
+
val.is_a?(Array) && val.all? { |x| is_polars_dtype(x) }
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.is_int_sequence(val)
|
193
|
+
val.is_a?(Array) && _is_iterable_of(val, Integer)
|
194
|
+
end
|
195
|
+
|
196
|
+
def self.is_expr_sequence(val)
|
197
|
+
val.is_a?(Array) && _is_iterable_of(val, Expr)
|
198
|
+
end
|
199
|
+
|
200
|
+
def self.is_rbexpr_sequence(val)
|
201
|
+
val.is_a?(Array) && _is_iterable_of(val, RbExpr)
|
202
|
+
end
|
203
|
+
|
184
204
|
def self.is_str_sequence(val, allow_str: false)
|
185
205
|
if allow_str == false && val.is_a?(String)
|
186
206
|
false
|
data/lib/polars/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: x86_64-darwin
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: andrew@ankane.org
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.4.
|
85
|
+
rubygems_version: 3.4.4
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Blazingly fast DataFrames for Ruby
|