Skip to content

GH-50436: [Ruby] Add ArrowFormat::TimestampArray.new(unit, values)#50445

Merged
kou merged 1 commit into
apache:mainfrom
kou:ruby-timestamp-array-new
Jul 9, 2026
Merged

GH-50436: [Ruby] Add ArrowFormat::TimestampArray.new(unit, values)#50445
kou merged 1 commit into
apache:mainfrom
kou:ruby-timestamp-array-new

Conversation

@kou

@kou kou commented Jul 9, 2026

Copy link
Copy Markdown
Member

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.

Copilot AI review requested due to automatic review settings July 9, 2026 09:30
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #50436 has been automatically assigned in GitHub to PR creator.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_convert so TimestampArray.new can accept a unit (and optionally [unit, time_zone]) and build the appropriate TimestampType.
  • Add TimestampType#pack_template so timestamp values can be packed into buffers like other primitive/temporal arrays.
  • Add a new TestTimestampArray test 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
@kou kou changed the title GH-50436: [Ruby] Add ArrowFormat::Timestamp.new(unit, values) GH-50436: [Ruby] Add ArrowFormat::TimestampArray.new(unit, values) Jul 9, 2026
Copilot AI review requested due to automatic review settings July 9, 2026 20:47
@kou kou force-pushed the ruby-timestamp-array-new branch from 9bb1581 to 4ebb2bf Compare July 9, 2026 20:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

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
Copilot AI review requested due to automatic review settings July 9, 2026 21:06
@kou kou force-pushed the ruby-timestamp-array-new branch from 4ebb2bf to 07128f7 Compare July 9, 2026 21:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +557 to +560
when ::Array
unit, time_zone = value
new(unit, time_zone)
when self
@kou

kou commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

+1

@kou kou merged commit 58a6ea2 into apache:main Jul 9, 2026
33 checks passed
@kou kou removed the awaiting committer review Awaiting committer review label Jul 9, 2026
@kou kou deleted the ruby-timestamp-array-new branch July 9, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants