-
Notifications
You must be signed in to change notification settings - Fork 186
Add UnionScalar
#8739
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
base: codex/union-nullability-propagation
Are you sure you want to change the base?
Add UnionScalar
#8739
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,16 @@ impl Scalar { | |
| return Ok(self.clone()); | ||
| } | ||
|
|
||
| // Union nullability is part of its variant dtypes, so the generic nullability-only cast | ||
| // below is not valid for unions. Keep all non-identity union casts unsupported until their | ||
| // semantics are defined. | ||
| if self.dtype().is_union() || target_dtype.is_union() { | ||
| vortex_bail!( | ||
| "non-identity union scalar cast from {} to {target_dtype} is not supported", | ||
| self.dtype() | ||
| ); | ||
| } | ||
|
Comment on lines
+27
to
+35
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interested in what people think about how we should deal with this |
||
|
|
||
| // Check for solely nullability casting. | ||
| if self.dtype().eq_ignore_nullability(target_dtype) { | ||
| // Cast from non-nullable to nullable or vice versa. | ||
|
|
@@ -58,13 +68,16 @@ impl Scalar { | |
| DType::Binary(_) => self.as_binary().cast(target_dtype), | ||
| DType::List(..) | DType::FixedSizeList(..) => self.as_list().cast(target_dtype), | ||
| DType::Struct(..) => self.as_struct().cast(target_dtype), | ||
| DType::Union(..) => todo!("TODO(connor)[Union]: unimplemented"), | ||
| DType::Union(..) => unreachable!("union casts are handled before scalar dispatch"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @connortsui20 I am saying you should fallback here in your cast
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't really understand here, what exactly do you mean by "falls back to union scalar"? We already have a union scalar in the input |
||
| DType::Variant(_) => vortex_bail!("Variant scalars can't be cast to {target_dtype}"), | ||
| DType::Extension(..) => self.as_extension().cast(target_dtype), | ||
| } | ||
| } | ||
|
|
||
| /// Cast the scalar into a nullable version of its current type. | ||
| /// | ||
| /// For a union this makes every variant nullable, since a union has no top-level nullability of | ||
| /// its own. | ||
| pub fn into_nullable(self) -> Scalar { | ||
| let (dtype, value) = self.into_parts(); | ||
| Self::try_new(dtype.as_nullable(), value) | ||
|
|
||
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.
I think you have to gate the other branch and make sure this falls back to union scalar
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.
what is the other branch?
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.
the one the comment refers to
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.
I don't think I understand, are you saying that it can somehow get past this gate?
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.
Basically @connortsui20 we should plumb this method fully such that we delegate to the match and fail there