GH-50436: [Ruby] Add ArrowFormat::TimestampArray.new(unit, values)#50445
Merged
Conversation
|
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the Ruby red-arrow-format API to make it easier to build Arrow timestamp arrays directly from Ruby values by allowing ArrowFormat::TimestampArray.new(unit, values) (via TimestampType.try_convert support), and adds a dedicated unit test for the new initialization behavior.
Changes:
- Add
TimestampType.try_convertsoTimestampArray.newcan accept a unit (and optionally[unit, time_zone]) and build the appropriateTimestampType. - Add
TimestampType#pack_templateso timestamp values can be packed into buffers like other primitive/temporal arrays. - Add a new
TestTimestampArraytest file covering initialization and equality behaviors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| ruby/red-arrow-format/lib/arrow-format/type.rb | Adds conversion and packing support for TimestampType needed for TimestampArray.new(unit, values) to work. |
| ruby/red-arrow-format/test/test-timestamp-array.rb | Introduces unit tests for ArrowFormat::TimestampArray initialization and equality semantics. |
Comment on lines
+555
to
+559
| unit = value | ||
| TimestampType.new(unit, nil) | ||
| when Array | ||
| unit, time_zone = value | ||
| TimestampType.new(unit, time_zone) |
Comment on lines
+24
to
+43
| sub_test_case("#initialize") do | ||
| def test_no_null | ||
| values = [ | ||
| @timestamp_2019_11_17_15_09_11, | ||
| @timestamp_2025_12_16_05_33_58, | ||
| ] | ||
| assert_equal(values, | ||
| ArrowFormat::TimestampArray.new(:second, values).to_a) | ||
| end | ||
|
|
||
| def test_mixed | ||
| values = [ | ||
| @timestamp_2019_11_17_15_09_11, | ||
| nil, | ||
| @timestamp_2025_12_16_05_33_58, | ||
| ] | ||
| assert_equal(values, | ||
| ArrowFormat::TimestampArray.new(:second, values).to_a) | ||
| end | ||
| end |
Comment on lines
+30
to
+32
| assert_equal(values, | ||
| ArrowFormat::TimestampArray.new(:second, values).to_a) | ||
| end |
ArrowFormat::Timestamp.new(unit, values)ArrowFormat::TimestampArray.new(unit, values)
9bb1581 to
4ebb2bf
Compare
Comment on lines
+30
to
+32
| assert_equal(values, | ||
| ArrowFormat::TimestampArray.new(:second, values).to_a) | ||
| end |
Comment on lines
+552
to
+560
| def try_convert(value) | ||
| case value | ||
| when Symbol | ||
| unit = value | ||
| new(unit, nil) | ||
| when Array | ||
| unit, time_zone = value | ||
| new(unit, time_zone) | ||
| when self |
4ebb2bf to
07128f7
Compare
Comment on lines
+557
to
+560
| when ::Array | ||
| unit, time_zone = value | ||
| new(unit, time_zone) | ||
| when self |
Member
Author
|
+1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Building a timestamp Arrow array from Ruby objects is convenient.
What changes are included in this PR?
Accept
ArrowFormat::TimestampArray.new(unit, values).Are these changes tested?
Yes.
Are there any user-facing changes?
Yes.
ArrowFormat::TimestampArray.new(unit, values)#50436