-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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: Added input validation for explode
operation in the array namespace
#19163
Changes from 2 commits
1a4d3a0
e985407
c08c06b
1e157ab
9ae63be
0b2ee80
57b8f23
cd34234
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 | ||
---|---|---|---|---|
|
@@ -30,6 +30,7 @@ pub enum ArrayFunction { | |||
#[cfg(feature = "array_count")] | ||||
CountMatches, | ||||
Shift, | ||||
Explode, | ||||
} | ||||
|
||||
impl ArrayFunction { | ||||
|
@@ -56,6 +57,7 @@ impl ArrayFunction { | |||
#[cfg(feature = "array_count")] | ||||
CountMatches => mapper.with_dtype(IDX_DTYPE), | ||||
Shift => mapper.with_same_dtype(), | ||||
Explode => mapper.map_to_list_and_array_inner_dtype(), | ||||
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 think you can do the dtype validation here - e.g. Explode => mapper.try_map_to_array_inner_dtype()?, Where 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. In fact, we could maybe even add a check before this match block to ensure the dtype is 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 don't think that's needed. As that check would be required on every
So I think it will resolve itself. During simplification of expressions we can then rewrite 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 see - then adding 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. @nameexhaustion @ritchie46 In addition, if we convert to So I propose -
What do you think? Edit: On Separate PR I will make all |
||||
} | ||||
} | ||||
} | ||||
|
@@ -96,6 +98,7 @@ impl Display for ArrayFunction { | |||
#[cfg(feature = "array_count")] | ||||
CountMatches => "count_matches", | ||||
Shift => "shift", | ||||
Explode => "explode", | ||||
}; | ||||
write!(f, "arr.{name}") | ||||
} | ||||
|
@@ -129,6 +132,7 @@ impl From<ArrayFunction> for SpecialEq<Arc<dyn ColumnsUdf>> { | |||
#[cfg(feature = "array_count")] | ||||
CountMatches => map_as_slice!(count_matches), | ||||
Shift => map_as_slice!(shift), | ||||
Explode => map!(explode), | ||||
} | ||||
} | ||||
} | ||||
|
@@ -249,3 +253,7 @@ pub(super) fn shift(s: &[Column]) -> PolarsResult<Column> { | |||
|
||||
ca.array_shift(n.as_materialized_series()).map(Column::from) | ||||
} | ||||
|
||||
pub(super) fn explode(s: &Column) -> PolarsResult<Column> { | ||||
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. This is not needed. |
||||
s.array()?.array_explode().map(Column::from) | ||||
} |
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 it on the namespace.