You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "emecii (via GitHub)" <gi...@apache.org> on 2026/09/10 04:37:20 UTC
[PR] GH-51271: [Ruby] Fix Date values in ArrowFormat::Date32Array [arrow]
emecii opened a new pull request, #51272:
URL: https://github.com/apache/arrow/pull/51272
### Rationale for this change
`ArrowFormat::Date32Array` currently stores `Date#day`, the day of the month, for Ruby `Date` values. Arrow Date32 values are signed day offsets from the Unix epoch, so this can silently produce incorrect data. The same conversion is used by `ArrowFormat::Array.build` when it infers Date32.
### What changes are included in this PR?
* Convert Ruby `Date` values from their Julian day to the Unix epoch day offset.
* Cover dates before, at, and after the Unix epoch, including nulls.
* Make the ArrayBuilder regression assert the encoded payload instead of comparing two arrays built through the same conversion path.
### Are these changes tested?
Yes. The full `red-arrow-format` suite passes locally: 691 tests and 695 assertions. The official rake runner used the current pure-Ruby sources with the locally installed Arrow 25.0.1 native extension; the local system does not have the Arrow C++ 26 dependency needed to build the native Ruby extension from `main`.
### Are there any user-facing changes?
Yes. Ruby `Date` values now produce specification-compliant Date32 day offsets.
**This PR contains a "Critical Fix".** It fixes incorrect Date32 data produced from Ruby `Date` values.
### AI assistance
AI assistance was used to investigate the defect, draft the focused implementation and tests, and run the verification described above. No human review is claimed.
* GitHub Issue: #51271
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-51271: [Ruby] Fix Date values in ArrowFormat::Date32Array [arrow]
Posted by "emecii (via GitHub)" <gi...@apache.org>.
emecii commented on code in PR #51272:
URL: https://github.com/apache/arrow/pull/51272#discussion_r3980981359
##########
ruby/red-arrow-format/test/test-array-builder.rb:
##########
@@ -144,7 +144,8 @@ def test_time
def test_date
values = [Date.new(2026, 7, 17)]
- assert_equal(ArrowFormat::Date32Array.new(values),
- ArrowFormat::Array.build(values))
+ array = ArrowFormat::Array.build(values)
+ assert_equal(ArrowFormat::Date32Array, array.class)
+ assert_equal([20651], array.to_a)
Review Comment:
Yes. `TestDate32Array#test_date` covers the Date conversion path (including pre-epoch, epoch, `nil`, and a modern date), so I restored the original `Date32Array.new == Array.build` assertion in b848efba51. Focused suites pass: 8/8 Date32 tests and 22/22 array-builder tests.
##########
ruby/red-arrow-format/lib/arrow-format/array.rb:
##########
@@ -489,11 +489,12 @@ def type
end
private
+ UNIX_EPOCH = 2440588
Review Comment:
Applied in b848efba51. I also added the explicit stdlib `date` require because this constant is evaluated while loading `arrow-format`; standalone loading and epoch conversion now pass, along with both focused suites.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-51271: [Ruby] Fix Date values in ArrowFormat::Date32Array [arrow]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #51272:
URL: https://github.com/apache/arrow/pull/51272
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-51271: [Ruby] Fix Date values in ArrowFormat::Date32Array [arrow]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #51272:
URL: https://github.com/apache/arrow/pull/51272#discussion_r3977050951
##########
ruby/red-arrow-format/lib/arrow-format/array.rb:
##########
@@ -489,11 +489,12 @@ def type
end
private
+ UNIX_EPOCH = 2440588
Review Comment:
```suggestion
UNIX_EPOCH = Date.new(1970, 1, 1).jd
```
##########
ruby/red-arrow-format/test/test-array-builder.rb:
##########
@@ -144,7 +144,8 @@ def test_time
def test_date
values = [Date.new(2026, 7, 17)]
- assert_equal(ArrowFormat::Date32Array.new(values),
- ArrowFormat::Array.build(values))
+ array = ArrowFormat::Array.build(values)
+ assert_equal(ArrowFormat::Date32Array, array.class)
+ assert_equal([20651], array.to_a)
Review Comment:
We can detect this case by the added `test_date` test in `test-date32-array.rb`, right?
If so, could you revert this change? We want to check `Date32Array.new == Array.build` here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org