jupyter_on_rails 0.4.2 → 0.5.0

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: 3b73af6425d6dc4c113600a8d92eb308bd1b1b73e10c6ddab45bbdee3eb003fa
4
- data.tar.gz: c0a23dffcb6ac10913e9f55770a8a047260157343aa8924afb604890a8366acc
3
+ metadata.gz: db480dd0b66703b18e2b2b381a2b7e8503dbbb7ad9a0d0602689059dc4b965b1
4
+ data.tar.gz: 0b7dfd212a1d16ba74d816a20e3273e73ec54838d8359501efad1755118e51c3
5
5
  SHA512:
6
- metadata.gz: 951f50bff513b74766689b6fabb39dc5f44943e40ae99bddcf2b171e66c807e9721f216553f3496f06cc64aa68b0c23d236333d6beaca941ef91d389041c41b3
7
- data.tar.gz: cfe80592f4e99248b307bb69474cf37b805b206519c1ebad4ca757ec9f82adaa1bcaaf33e829359f8c26ed362bd27900fb433ed8db6e23fb55f99818406129f2
6
+ metadata.gz: 3378f5acca6859363fe341814b483f0a8e70c0c8577497aec33330a8866ea733e87c04947a16110706bf4a207105ff846a328147b7f149f98f22d5ca226cb525
7
+ data.tar.gz: 5ecb5de5b600ba2d83cf045770c9ab0c1cd9d23181f15b57942bc0f23d7a566463c469926bdabf336cd2b76b91fb81227b0a44887aedf36f661f558faae676a1
@@ -5,8 +5,33 @@ module JupyterOnRails
5
5
  module ActiveRecordExt
6
6
  extend ::ActiveSupport::Concern
7
7
 
8
- included do
9
- scope :to_df, -> { ::Daru::DataFrame.from_activerecord(self) }
8
+ class_methods do
9
+ def to_df
10
+ relation = all
11
+ loaded_associations =
12
+ %i[includes_values preload_values eager_load_values]
13
+ .map(&relation.method(:send)).reduce(&:|)
14
+
15
+ datas = relation.flat_map do |record|
16
+ ret = [record.attributes.symbolize_keys]
17
+ loaded_associations.each do |assoc|
18
+ ret = ret.flat_map do |attrs|
19
+ assocs = record.send(assoc)
20
+ next [attrs] unless assocs.present?
21
+
22
+ assocs.map(&:attributes).map do |assoc_attrs|
23
+ new_attrs = assoc_attrs.transform_keys do |key|
24
+ "#{assoc}.#{key}".to_sym
25
+ end
26
+ attrs.merge(new_attrs)
27
+ end
28
+ end
29
+ end
30
+ ret
31
+ end
32
+
33
+ ::Daru::DataFrame.new(datas)
34
+ end
10
35
  end
11
36
  end
12
37
  end
@@ -1,3 +1,3 @@
1
1
  module JupyterOnRails
2
- VERSION = '0.4.2'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jupyter_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki INOUE