-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/type preservation empty dataframes #301
Open
dan-corneanu
wants to merge
2
commits into
red-data-tools:main
Choose a base branch
from
dan-corneanu:fix/type-preservation-empty-dataframes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix/type preservation empty dataframes #301
dan-corneanu
wants to merge
2
commits into
red-data-tools:main
from
dan-corneanu:fix/type-preservation-empty-dataframes
Conversation
This file contains 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
kou
reviewed
Jan 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a fix to this PR?
diff --git a/lib/red_amber/data_frame_variable_operation.rb b/lib/red_amber/data_frame_variable_operation.rb
index 7a5179e..62b0706 100755
--- a/lib/red_amber/data_frame_variable_operation.rb
+++ b/lib/red_amber/data_frame_variable_operation.rb
@@ -675,9 +675,18 @@ module RedAmber
raise DataFrameArgumentError, "Data size mismatch (#{data.size} != #{size})"
end
- a = Arrow::Array.new(data.is_a?(Vector) ? data.to_a : data)
+ if data.respond_to?(:to_arrow_chunked_array)
+ chunked_array = data.to_arrow_chunked_array
+ else
+ if data.respond_to?(:to_arrow_array)
+ a = data.to_arrow_array
+ else
+ a = Arrow::Array.new(data)
+ end
+ chunked_array = Arrow::ChunkedArray.new([a])
+ end
fields[i] = Arrow::Field.new(key, a.value_data_type)
- arrays[i] = Arrow::ChunkedArray.new([a])
+ arrays[i] = chunked_array
end
[fields, arrays]
end
diff --git a/lib/red_amber/vector.rb b/lib/red_amber/vector.rb
index 7237807..5267eb6 100644
--- a/lib/red_amber/vector.rb
+++ b/lib/red_amber/vector.rb
@@ -198,6 +198,22 @@ module RedAmber
alias_method :values, :to_ary
alias_method :entries, :to_ary
+ # Convert to an Arrow::Array.
+ #
+ # @return [Arrow::Array]
+ # Apache Arrow array representation.
+ def to_arrow_array
+ @data.to_arrow_array
+ end
+
+ # Convert to an Arrow::ChunkedArray.
+ #
+ # @return [Arrow::ChunkedArray]
+ # Apache Arrow chunked array representation.
+ def to_arrow_chunked_array
+ @data.to_arrow_chunked_array
+ end
+
# Indeces from 0 to size-1 by Array.
#
# @return [Array]
@@ -439,6 +439,22 @@ class DataFrameVariableOperationTest < Test::Unit::TestCase | |||
assert_equal str2, @df2.assign { assigner2.to_a }.tdr_str | |||
end | |||
|
|||
sub_test_case 'Dataframe with zero n_records' do | |||
test 'assign by block' do | |||
assert_equal :double, @df.b.type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this.
Suggested change
assert_equal :double, @df.b.type |
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.
It looks like manipulating a column in an empty data frame defaults the result to a type of
:string
.