Skip to content

Commit

Permalink
GH-45119: [Ruby] Use #size for Arrow::Column#size backend (#45133)
Browse files Browse the repository at this point in the history
### Rationale for this change

`#n_rows` is available only on `Arrow::ChunkedArray`. It's not available on `Arrow::Array`.

### What changes are included in this PR?

It's available on both of `Arrow::Array` and `Arrow::ChunkedArray`.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

Yes.
* GitHub Issue: #45119

Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
kou authored Dec 31, 2024
1 parent cc56f12 commit 71c4b88
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ruby/red-arrow/lib/arrow/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def reverse_each(&block)
@data.reverse_each(&block)
end

def n_rows
@data.n_rows
def size
@data.size
end
alias_method :size, :n_rows
alias_method :length, :n_rows
alias_method :length, :size
alias_method :n_rows, :size

def n_nulls
@data.n_nulls
Expand Down
8 changes: 8 additions & 0 deletions ruby/red-arrow/test/test-column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def setup
assert_equal([false, nil, true], @column.reverse_each.to_a)
end

test("#size") do
assert_equal(3, @column.size)
end

test("#length") do
assert_equal(3, @column.length)
end

test("#n_rows") do
assert_equal(3, @column.n_rows)
end
Expand Down
6 changes: 6 additions & 0 deletions ruby/red-arrow/test/test-record-batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,11 @@ def setup
@record_batch[[:c, "a", -1, 3..4]])
end
end

sub_test_case("#column") do
test("#size") do
assert_equal(@counts.size, @record_batch[:count].size)
end
end
end
end

0 comments on commit 71c4b88

Please sign in to comment.