Method: Arrow::ColumnContainable#select_columns
- Defined in:
- lib/arrow/column-containable.rb
#select_columns(*selectors) {|column| ... } ⇒ self.class
Selects columns that are selected by selectors and/or block and creates a new container only with the selected columns.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/arrow/column-containable.rb', line 74 def select_columns(*selectors, &block) if selectors.empty? return to_enum(__method__) unless block_given? selected_columns = columns.select(&block) else selected_columns = [] selectors.each do |selector| case selector when Range selected_columns.concat(columns[selector]) else column = find_column(selector) if column.nil? case selector when String, Symbol = "unknown column: #{selector.inspect}: #{inspect}" raise KeyError.new() else = "out of index (0..#{n_columns - 1}): " << "#{selector.inspect}: #{inspect}" raise IndexError.new() end end selected_columns << column end end selected_columns = selected_columns.select(&block) if block_given? end self.class.new(selected_columns) end |