Repository navigation
fix: handle missing values in column profiling #1150
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
Merged
andreatnvidia
merged 3 commits into
NVIDIA-NeMo:main
from
williamcaban:williamcaban/fix/1144-profiling-missing-values
Nov 11, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
111 changes: 111 additions & 0 deletions
111
packages/data-designer/tests/interface/test_profiling_statistics.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pandas as pd | ||
| import pytest | ||
|
|
||
| from data_designer.config.analysis.column_statistics import ColumnDistributionType, NumericalDistribution | ||
| from data_designer.config.column_configs import ExpressionColumnConfig, SamplerColumnConfig | ||
| from data_designer.config.config_builder import DataDesignerConfigBuilder | ||
| from data_designer.config.models import ModelProvider | ||
| from data_designer.config.run_config import ResumeMode, RunConfig | ||
| from data_designer.config.sampler_params import SamplerType, UniformSamplerParams | ||
| from data_designer.config.seed_source_dataframe import DataFrameSeedSource | ||
| from data_designer.engine.secret_resolver import PlaintextResolver | ||
| from data_designer.interface.data_designer import DataDesigner | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def designer(tmp_path: Path, stub_model_providers: list[ModelProvider]) -> DataDesigner: | ||
| managed = tmp_path / "managed" | ||
| managed.mkdir() | ||
| designer = DataDesigner( | ||
| artifact_path=tmp_path / "artifacts", | ||
| model_providers=stub_model_providers, | ||
| secret_resolver=PlaintextResolver(), | ||
| managed_assets_path=managed, | ||
| ) | ||
| designer.set_run_config(RunConfig(otel_metrics_port=None)) | ||
| return designer | ||
|
|
||
|
|
||
| def _statistics(analysis, column_name: str): | ||
| return next(stat for stat in analysis.column_statistics if stat.column_name == column_name) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("run", ["preview", "create"]) | ||
| @pytest.mark.parametrize( | ||
| "values", | ||
| [ | ||
| pytest.param(pd.Series([7, None], dtype="Int64"), id="nullable-int"), | ||
| pytest.param(pd.Series(["a", None], dtype="string"), id="nullable-string"), | ||
| pytest.param(pd.Series([True, None], dtype="boolean"), id="nullable-boolean"), | ||
| ], | ||
| ) | ||
| def test_profile_counts_a_missing_seed_value_as_null_not_as_a_distinct_value( | ||
| designer: DataDesigner, values: pd.Series, run: str | ||
| ) -> None: | ||
| config = DataDesignerConfigBuilder().with_seed_dataset(DataFrameSeedSource(df=pd.DataFrame({"value": values}))) | ||
| config.add_column( | ||
| ExpressionColumnConfig(name="rendered", expr="{{ 'MISSING' if value is none else 'PRESENT' }}", dtype="str") | ||
| ) | ||
|
|
||
| if run == "preview": | ||
| analysis = designer.preview(config, num_records=2).analysis | ||
| else: | ||
| analysis = designer.create(config, num_records=2, dataset_name="profile_nulls").load_analysis() | ||
|
|
||
| statistics = _statistics(analysis, "value") | ||
| assert statistics.num_null == 1 | ||
| assert statistics.num_unique == 1 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("run", ["preview", "create"]) | ||
| def test_profile_keeps_the_distribution_of_a_single_record_numerical_sampler(designer: DataDesigner, run: str) -> None: | ||
| config = DataDesignerConfigBuilder() | ||
| config.add_column( | ||
| SamplerColumnConfig(name="value", sampler_type=SamplerType.UNIFORM, params=UniformSamplerParams(low=0, high=10)) | ||
| ) | ||
|
|
||
| if run == "preview": | ||
| result = designer.preview(config, num_records=1) | ||
| analysis, dataset = result.analysis, result.dataset | ||
| else: | ||
| created = designer.create(config, num_records=1, dataset_name="profile_single") | ||
| analysis, dataset = created.load_analysis(), created.load_dataset() | ||
|
|
||
| statistics = _statistics(analysis, "value") | ||
| assert statistics.distribution_type == ColumnDistributionType.NUMERICAL | ||
| sampled = float(dataset["value"].iloc[0]) | ||
| assert statistics.distribution.min == pytest.approx(sampled, abs=0.01) | ||
| assert statistics.distribution.max == pytest.approx(sampled, abs=0.01) | ||
| assert statistics.distribution.mean == pytest.approx(sampled, abs=0.01) | ||
| assert statistics.distribution.median == pytest.approx(sampled, abs=0.01) | ||
| assert statistics.distribution.stddev != statistics.distribution.stddev # NaN: undefined for one record | ||
|
|
||
|
|
||
| def test_single_record_distribution_survives_saved_metadata_and_resume(designer: DataDesigner) -> None: | ||
| config = DataDesignerConfigBuilder() | ||
| config.add_column( | ||
| SamplerColumnConfig(name="value", sampler_type=SamplerType.UNIFORM, params=UniformSamplerParams(low=0, high=10)) | ||
| ) | ||
|
|
||
| created = designer.create(config, num_records=1, dataset_name="profile_resume") | ||
| saved = created.artifact_storage.read_metadata()["column_statistics"][0]["distribution"] | ||
| reloaded = NumericalDistribution.model_validate(saved) | ||
| sampled = float(created.load_dataset()["value"].iloc[0]) | ||
| assert reloaded.mean == pytest.approx(sampled, abs=0.01) | ||
| assert reloaded.stddev != reloaded.stddev # NaN survives the JSON round trip | ||
|
|
||
| resumed = designer.create(config, num_records=1, dataset_name="profile_resume", resume=ResumeMode.ALWAYS) | ||
| statistics = _statistics(resumed.load_analysis(), "value") | ||
| assert statistics.distribution.mean == pytest.approx(sampled, abs=0.01) | ||
| assert statistics.distribution.stddev != statistics.distribution.stddev | ||
| resaved = NumericalDistribution.model_validate( | ||
| resumed.artifact_storage.read_metadata()["column_statistics"][0]["distribution"] | ||
| ) | ||
| assert resaved.stddev != resaved.stddev | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.