Class: Arrow::DataType
- Inherits:
-
Object
- Object
- Arrow::DataType
- Defined in:
- lib/arrow/data-type.rb
Class Method Summary collapse
-
.resolve(data_type) ⇒ Object
Ensure returning suitable DataType.
- .sub_types ⇒ Object
- .try_convert(value) ⇒ Object
Instance Method Summary collapse
- #array_class ⇒ Object
- #build_array(values) ⇒ Object
-
#scalar_class ⇒ Arrow::Scalar
A corresponding Scalar class for this data type.
Class Method Details
.resolve(data_type) ⇒ Arrow::DataType .resolve(name) ⇒ Arrow::DataType .resolve(name_with_arguments) ⇒ Arrow::DataType .resolve(description) ⇒ Arrow::DataType
Ensure returning suitable Arrow::DataType.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/arrow/data-type.rb', line 92 def resolve(data_type) case data_type when DataType data_type when String, Symbol resolve_class(data_type).new when ::Array type, *arguments = data_type resolve_class(type).new(*arguments) when Hash type = nil description = {} data_type.each do |key, value| key = key.to_sym case key when :type type = value else description[key] = value end end if type.nil? and self == DataType = "data type description must have :type value: #{data_type.inspect}" raise ArgumentError, end data_type_class = resolve_class(type) if description.empty? data_type_class.new else data_type_class.new(description) end else = "data type must be " + "Arrow::DataType, String, Symbol, [String, ...], [Symbol, ...] " + "{type: String, ...} or {type: Symbol, ...}: #{data_type.inspect}" raise ArgumentError, end end |
.sub_types ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/arrow/data-type.rb', line 133 def sub_types types = {} gtype.children.each do |child| sub_type = child.to_class types[sub_type] = true sub_type.sub_types.each do |sub_sub_type| types[sub_sub_type] = true end end types.keys end |
.try_convert(value) ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/arrow/data-type.rb', line 145 def try_convert(value) begin resolve(value) rescue ArgumentError nil end end |
Instance Method Details
#array_class ⇒ Object
191 192 193 194 |
# File 'lib/arrow/data-type.rb', line 191 def array_class base_name = self.class.name.gsub(/DataType\z/, "") ::Arrow.const_get("#{base_name}Array") end |
#build_array(values) ⇒ Object
196 197 198 199 200 201 |
# File 'lib/arrow/data-type.rb', line 196 def build_array(values) builder_class = array_class.builder_class args = [values] args.unshift(self) unless builder_class.buildable?(args) builder_class.build(*args) end |
#scalar_class ⇒ Arrow::Scalar
Returns A corresponding Scalar class for this data type.
207 208 209 210 |
# File 'lib/arrow/data-type.rb', line 207 def scalar_class base_name = self.class.name.gsub(/DataType\z/, "") ::Arrow.const_get("#{base_name}Scalar") end |