-
Notifications
You must be signed in to change notification settings - Fork 2
fix: raise group by column not found error #374
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
nina-xu
merged 6 commits into
main
from
nina-xu/176-error-out-group-by-column-not-found
Apr 16, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bb07255
fail early at holdout step if group by column is missing
nina-xu cb85128
refactor validation now that we also check for comma in the name
nina-xu 879dc0f
make format
nina-xu 673867d
dedupe tests
nina-xu 040f078
revert nit change
nina-xu de92dd3
Revert "revert nit change"
nina-xu 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Data validation helpers shared across pipeline stages.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Collection | ||
|
|
||
| import pandas as pd | ||
|
|
||
| from ..errors import DataError, ParameterError | ||
|
|
||
| MISSING_GROUP_BY_COLUMN_ERROR = "Group by column '{group_by}' not found in input dataset columns. " | ||
| MISSING_GROUP_BY_VALUES_ERROR = "Group by column '{group_by}' has missing values. Please remove/replace them." | ||
| MISSING_ORDER_BY_COLUMN_ERROR = "Order by column '{order_by}' not found in the input data." | ||
|
|
||
|
|
||
| def _get_column_names(data: pd.DataFrame | Collection[str]) -> Collection[str]: | ||
| if isinstance(data, pd.DataFrame): | ||
| return data.columns | ||
| return data | ||
|
|
||
|
|
||
| def validate_groupby_column(data: pd.DataFrame | Collection[str], group_by: str | None) -> None: | ||
|
nina-xu marked this conversation as resolved.
|
||
| """Validate that the configured group-by column exists and has no missing values. | ||
|
|
||
| Args: | ||
| data: A DataFrame or collection of column names to validate against. | ||
| group_by: Name of the configured grouping column. | ||
|
|
||
| Raises: | ||
| ParameterError: If ``group_by`` is configured but not present in ``data``. | ||
| DataError: If ``data`` is a DataFrame and ``group_by`` contains missing values. | ||
| """ | ||
| if group_by is None: | ||
| return | ||
|
|
||
| columns = _get_column_names(data) | ||
|
|
||
| if group_by not in columns: | ||
| message = MISSING_GROUP_BY_COLUMN_ERROR.format(group_by=group_by) | ||
| if "," in group_by: | ||
| message += ( | ||
| " The column name contains a comma -- multi-column grouping is not supported. Use a single column name." | ||
| ) | ||
| else: | ||
| message += " Please set `data.group_training_examples_by` to an existing column or to `null`/`None` to disable grouping." | ||
| raise ParameterError(message) | ||
|
|
||
| if isinstance(data, pd.DataFrame) and data[group_by].isna().any(): | ||
| raise DataError(MISSING_GROUP_BY_VALUES_ERROR.format(group_by=group_by)) | ||
|
|
||
|
|
||
| def validate_orderby_column(data: pd.DataFrame | Collection[str], order_by: str | None) -> None: | ||
| """Validate that the configured order-by column exists. | ||
|
|
||
| Args: | ||
| data: A DataFrame or collection of column names to validate against. | ||
| order_by: Name of the configured ordering column. | ||
|
|
||
| Raises: | ||
| ParameterError: If ``order_by`` is configured but not present in ``data``. | ||
| """ | ||
| if order_by is None: | ||
| return | ||
|
|
||
| columns = _get_column_names(data) | ||
|
|
||
| if order_by not in columns: | ||
| raise ParameterError(MISSING_ORDER_BY_COLUMN_ERROR.format(order_by=order_by)) | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import pandas as pd | ||
| import pytest | ||
|
|
||
| from nemo_safe_synthesizer.data_processing.validation import ( | ||
| validate_groupby_column, | ||
| validate_orderby_column, | ||
| ) | ||
| from nemo_safe_synthesizer.errors import DataError, ParameterError | ||
|
|
||
|
|
||
| def test_validate_groupby_column_noop_when_groupby_is_none() -> None: | ||
| df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}) | ||
| validate_groupby_column(df, None) | ||
|
|
||
|
|
||
| def test_validate_groupby_column_passes_when_column_exists() -> None: | ||
| df = pd.DataFrame( | ||
| { | ||
| "col1": [1, 2, 3, 4, 5], | ||
| "col2": ["a", "b", "c", "d", "e"], | ||
| "group_col": ["g1", "g1", "g2", "g2", "g3"], | ||
| } | ||
| ) | ||
| validate_groupby_column(df, "group_col") | ||
|
|
||
|
|
||
| def test_validate_groupby_column_raises_for_missing_column() -> None: | ||
| df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}) | ||
| with pytest.raises( | ||
| ParameterError, | ||
| match=r"Group by column 'missing_group' not found in input dataset columns.*disable grouping", | ||
| ): | ||
| validate_groupby_column(df, "missing_group") | ||
|
|
||
|
|
||
| def test_validate_groupby_column_raises_for_comma_in_name() -> None: | ||
| df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}) | ||
| with pytest.raises(ParameterError, match="multi-column grouping is not supported"): | ||
| validate_groupby_column(df, "col1,col2") | ||
|
|
||
|
|
||
| def test_validate_groupby_column_raises_for_missing_values() -> None: | ||
| df = pd.DataFrame({"group": ["x", None], "value": [1, 2]}) | ||
| with pytest.raises(DataError, match="missing values"): | ||
| validate_groupby_column(df, "group") | ||
|
|
||
|
|
||
| def test_validate_orderby_column_noop_when_orderby_is_none() -> None: | ||
| df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}) | ||
| validate_orderby_column(df, None) | ||
|
|
||
|
|
||
| def test_validate_orderby_column_raises_for_missing_column() -> None: | ||
| df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}) | ||
| with pytest.raises(ParameterError, match="not found in the input data"): | ||
| validate_orderby_column(df, "missing_order") |
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
Oops, something went wrong.
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.