kou commented on code in PR #15089:
URL: https://github.com/apache/arrow/pull/15089#discussion_r1056999194
##########
ruby/red-arrow/lib/arrow/table.rb:
##########
@@ -426,6 +426,14 @@ def remove_column(name_or_index)
remove_column_raw(index)
end
+ # Return column names in an Array.
+ #
+ # @return [::Array<String>] column names.
+ #
Review Comment:
```suggestion
#
# @since 11.0.0
```
##########
ruby/red-arrow/test/test-table.rb:
##########
@@ -602,6 +602,18 @@ def setup
end
end
+ sub_test_case("#column_names") do
+ test ("unique names") do
+ table = Arrow::Table.new(a: [1], b: [2], c: [3])
+ assert_equal(%w[a b c], table.column_names)
+ end
+
+ test ("duplicated names") do
Review Comment:
```suggestion
test("duplicated") do
```
##########
ruby/red-arrow/test/test-table.rb:
##########
@@ -602,6 +602,18 @@ def setup
end
end
+ sub_test_case("#column_names") do
+ test ("unique names") do
Review Comment:
```suggestion
test("unique") do
```
##########
ruby/red-arrow/lib/arrow/table.rb:
##########
@@ -426,6 +426,14 @@ def remove_column(name_or_index)
remove_column_raw(index)
end
+ # Return column names in an Array.
Review Comment:
```suggestion
# Return column names in this table.
```
##########
ruby/red-arrow/lib/arrow/table.rb:
##########
@@ -426,6 +426,14 @@ def remove_column(name_or_index)
remove_column_raw(index)
end
+ # Return column names in an Array.
+ #
+ # @return [::Array<String>] column names.
+ #
+ def column_names
+ columns.map(&:name)
+ end
Review Comment:
How about defining this in `Arrow::ColumnContainable`?
##########
ruby/red-arrow/lib/arrow/table.rb:
##########
@@ -426,6 +426,14 @@ def remove_column(name_or_index)
remove_column_raw(index)
end
+ # Return column names in an Array.
+ #
+ # @return [::Array<String>] column names.
+ #
+ def column_names
+ columns.map(&:name)
Review Comment:
How about caching the result because column information is immutable.
```suggestion
@column_names ||= columns.map(&:name)
```
FYI: I prefer `ma` to `collect`. :-)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]