Skip to content

Commit

Permalink
ARROW-7455: [Ruby] Use Arrow::DataType.resolve for all GArrowDataType…
Browse files Browse the repository at this point in the history
… input

Closes apache#6079 from kou/ruby-cast-data-type and squashes the following commits:

ab3bf87 <Sutou Kouhei>  Use Arrow::DataType.resolve for all GArrowDataType input

Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Krisztián Szűcs <[email protected]>
  • Loading branch information
kou authored and kszucs committed Dec 22, 2019
1 parent e77cff0 commit 4b32c7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ruby/red-arrow/lib/arrow/data-type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ def sub_types
types.keys
end

def try_convert(value)
begin
resolve(value)
rescue ArgumentError
nil
end
end

private
def resolve_class(data_type)
components = data_type.to_s.split("_").collect(&:capitalize)
Expand Down
7 changes: 7 additions & 0 deletions ruby/red-arrow/test/test-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def setup
end
end
end

sub_test_case("#cast") do
test("Symbol") do
assert_equal(Arrow::Int32Array.new([1, 2, 3]),
Arrow::StringArray.new(["1", "2", "3"]).cast(:int32))
end
end
end

sub_test_case("#filter") do
Expand Down

0 comments on commit 4b32c7d

Please sign in to comment.