GH-50435: [Ruby] Add ArrowFormat::Time{32,64}.new(unit, values)#50443
Merged
Conversation
ArrowFormat::Time{32,64}.new(values)ArrowFormat::Time{32,64}.new(unit, values)
|
|
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 construct Arrow Time32/Time64 arrays directly from Ruby values by allowing the unit to be passed as a symbol and by enabling packing for these temporal types.
Changes:
- Add
pack_templateimplementations forTime32TypeandTime64TypesoPrimitiveArraycan pack Ruby values into the values buffer. - Extend
Time32Array/Time64Arrayinitialization to accept a unitSymbol(e.g.,:second,:microsecond) and coerce it into the correspondingTime{32,64}Type. - Add new unit tests covering initialization and equality/slicing behavior for
Time32ArrayandTime64Array.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ruby/red-arrow-format/lib/arrow-format/array.rb | Adds type coercion hook so Time32Array/Time64Array can accept a unit symbol. |
| ruby/red-arrow-format/lib/arrow-format/type.rb | Adds packing templates for Time32Type/Time64Type to support building arrays from Ruby values. |
| ruby/red-arrow-format/test/test-time32-array.rb | New tests for building and comparing Time32Array from Ruby values (including nils and slicing). |
| ruby/red-arrow-format/test/test-time64-array.rb | New tests for building and comparing Time64Array from Ruby values (including nils and slicing). |
Comment on lines
+469
to
+477
| def ensure_type(type) | ||
| case type | ||
| when Symbol | ||
| unit = type | ||
| Time32Type.new(unit) | ||
| else | ||
| type | ||
| end | ||
| end |
Comment on lines
+482
to
+490
| def ensure_type(type) | ||
| case type | ||
| when Symbol | ||
| unit = type | ||
| Time64Type.new(unit) | ||
| else | ||
| type | ||
| end | ||
| end |
Comment on lines
193
to
197
| else | ||
| type = args.shift | ||
| type = self.class.type_class.try_convert(type) || type | ||
| expected_n_args = "2 or 4" | ||
| end |
Comment on lines
194
to
+197
| type = args.shift | ||
| unless type.is_a?(Type) | ||
| type = self.class.type_class.try_convert(type) || type | ||
| end |
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 time{32,64} Arrow array from Ruby objects is convenient.
What changes are included in this PR?
Accept
ArrowFormat::Time{32,64}.new(unit, values).Are these changes tested?
Yes.
Are there any user-facing changes?
Yes.
ArrowFormat::Time{32,64}.new(unit, values)#50435