feat: add DataFrame fill_nan#22702
Open
Nagato-Yuzuru wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new fill_nan method to DataFrame that replaces NaN values in floating-point columns with a user-provided scalar, leveraging the nanvl math function. Includes tests for both column-scoped and all-columns variants.
Changes:
- New
DataFrame::fill_nan(value, columns)API that builds a projection withnanvl(col, fill_value)for matching float columns. - Falls back to the original column when the fill value cannot be cast to the column type.
- Adds two tokio tests verifying behavior for specified columns and for all columns.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| datafusion/core/src/dataframe/mod.rs | Implements fill_nan using nanvl, with column resolution and type-cast handling. |
| datafusion/core/tests/dataframe/mod.rs | Adds create_nan_table helper and tests for fill_nan. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2582
to
+2593
| match value.clone().cast_to(field.data_type()) { | ||
| Ok(fill_value) => Expr::Alias(Alias { | ||
| expr: Box::new(Expr::ScalarFunction(ScalarFunction { | ||
| func: nanvl(), | ||
| args: vec![col(field.name()), lit(fill_value)], | ||
| })), | ||
| relation: None, | ||
| name: field.name().to_string(), | ||
| metadata: None, | ||
| }), | ||
| Err(_) => col(field.name()), | ||
| } |
| }) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| self.clone().select(projections) |
| Ok(()) | ||
| } | ||
|
|
||
| async fn create_nan_table() -> Result<DataFrame> { |
This file contains hidden or 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
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.
Which issue does this PR close?
What changes are included in this PR?
Add
fill_nanand test by referencing thefill_nullmirror.Are these changes tested?
Yes
Are there any user-facing changes?
Add a new function.