class Charty::TableAdapters::PandasDataFrameAdapter::GroupBy
Public Class Methods
new(groupby)
click to toggle source
# File lib/charty/table_adapters/pandas_adapter.rb, line 143 def initialize(groupby) @groupby = groupby end
Public Instance Methods
[](key)
click to toggle source
# File lib/charty/table_adapters/pandas_adapter.rb, line 205 def [](key) Charty::Table.new(@groupby.get_group(key)) end
apply(*args, &block)
click to toggle source
# File lib/charty/table_adapters/pandas_adapter.rb, line 197 def apply(*args, &block) res = @groupby.apply(->(data) { res = block.call(Charty::Table.new(data), *args) Pandas::Series.new(data: res) }) Charty::Table.new(res) end
each_group() { |Array(key), self| ... }
click to toggle source
TODO: test
# File lib/charty/table_adapters/pandas_adapter.rb, line 189 def each_group return enum_for(__method__) unless block_given? each_group_key do |key| yield(Array(key), self[key]) end end
each_group_key() { |key| ... }
click to toggle source
TODO: test
# File lib/charty/table_adapters/pandas_adapter.rb, line 158 def each_group_key return enum_for(__method__) unless block_given? if PyCall.respond_to?(:iterable) PyCall.iterable(@groupby).each do |key, index| if key.class == PyCall.builtins.tuple key = key.to_a end yield key end else # TODO: Remove this clause after the new PyCall will be released iter = @groupby.__iter__() while true begin key, sub_data = iter.__next__ if key.class == PyCall.builtins.tuple key = key.to_a end yield key rescue PyCall::PyError => error if error.type == PyCall.builtins.StopIteration break else raise error end end end end end
group_keys()
click to toggle source
# File lib/charty/table_adapters/pandas_adapter.rb, line 153 def group_keys each_group_key.to_a end
indices()
click to toggle source
# File lib/charty/table_adapters/pandas_adapter.rb, line 147 def indices @groupby.indices.map { |k, v| [k, v.to_a] }.to_h end