-
Notifications
You must be signed in to change notification settings - Fork 819
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
Add PrimitiveArray::try_new (#3879) #4067
Conversation
d74b35e
to
b50bc34
Compare
b50bc34
to
1f869af
Compare
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.
Can you please add a test of this new code, ideally also exercising the error path as well?
if let Some(n) = nulls.as_ref() { | ||
assert_eq!(values.len(), n.len()); | ||
if n.len() != values.len() { |
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.
Is this redundant with checks from ArrayData. Is it inevitable that we'll have redundancy between the checks?
I am thinking of https://docs.rs/arrow/latest/arrow/array/struct.ArrayData.html#method.validate and friends
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.
In the long-run we may be able to share code, but as the types of the buffers and the already validated constraints are different, I think some redundancy is inevitable. Fortunately most of this logic is fairly straightforward
assert_eq!(values.len(), n.len()); | ||
if n.len() != values.len() { | ||
return Err(ArrowError::InvalidArgumentError(format!( | ||
"Incorrect number of nulls for PrimitiveArray, expected {} got {}", |
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.
number of nulls
could be confused.
"Incorrect number of nulls for PrimitiveArray, expected {} got {}", | |
"Incorrect length of null buffer for PrimitiveArray, expected {} got {}", |
Which issue does this PR close?
Part of #3879
Rationale for this change
Some codebases may want to avoid panicking, and whilst for PrimitiveArray the necessary checks are pretty inconsequential, for consistency we should provide a try_new method for all arrays.
What changes are included in this PR?
Are there any user-facing changes?