lib/arrow/table.rb in red-arrow-0.17.1 vs lib/arrow/table.rb in red-arrow-1.0.0
- old
+ new
@@ -13,10 +13,12 @@
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+require "arrow/raw-table-converter"
+
module Arrow
class Table
include ColumnContainable
include GenericFilterable
include GenericTakeable
@@ -79,18 +81,10 @@
# @param raw_table [Hash<String, ::Array>]
# The pairs of column name and values of the table. Column values is
# `Array`.
#
# @example Create a table from column name and values
- # count_chunks = [
- # Arrow::UInt32Array.new([0, 2]),
- # Arrow::UInt32Array.new([nil, 4]),
- # ]
- # visible_chunks = [
- # Arrow::BooleanArray.new([true]),
- # Arrow::BooleanArray.new([nil, nil, false]),
- # ]
# Arrow::Table.new("count" => [0, 2, nil, 4],
# "visible" => [true, nil, nil, false])
#
# @overload initialize(schema, columns)
#
@@ -167,25 +161,12 @@
# Arrow::Table.new(schema, raw_records)
def initialize(*args)
n_args = args.size
case n_args
when 1
- if args[0][0].is_a?(Column)
- columns = args[0]
- fields = columns.collect(&:field)
- values = columns.collect(&:data)
- schema = Schema.new(fields)
- else
- raw_table = args[0]
- fields = []
- values = []
- raw_table.each do |name, array|
- array = ArrayBuilder.build(array) if array.is_a?(::Array)
- fields << Field.new(name.to_s, array.value_data_type)
- values << array
- end
- schema = Schema.new(fields)
- end
+ raw_table_converter = RawTableConverter.new(args[0])
+ schema = raw_table_converter.schema
+ values = raw_table_converter.values
when 2
schema = args[0]
schema = Schema.new(schema) unless schema.is_a?(Schema)
values = args[1]
case values[0]