fix: normalise string inputs to lists in ColumnMapping feature fields#1871
Open
YousefZahran1 wants to merge 1 commit intoevidentlyai:mainfrom
Open
fix: normalise string inputs to lists in ColumnMapping feature fields#1871YousefZahran1 wants to merge 1 commit intoevidentlyai:mainfrom
YousefZahran1 wants to merge 1 commit intoevidentlyai:mainfrom
Conversation
ColumnMapping.datetime_features (and the three sibling fields) are typed
as Optional[List[str]], but users reasonably pass a plain string. When a
string was stored the downstream check
column_name in mapping.datetime_features
became a substring test instead of a list-membership test. This caused a
column whose name merely *contains* the prediction column name (e.g.
'prediction_timestamp_utc') to be misclassified as the prediction column,
triggering a spurious ColumnType.Datetime error.
Fix: add __post_init__ to ColumnMapping that wraps any bare string in a
one-element list for datetime_features, categorical_features,
numerical_features, and text_features.
Fixes evidentlyai#846
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.
What
ColumnMapping.datetime_features(and the three sibling fieldscategorical_features,numerical_features,text_features) are typedOptional[List[str]], but a user who passes a plain string gets silent, incorrect behaviour: the downstream checkcolumn_name in mapping.datetime_featuresbecomes a substring test instead of a list-membership test.Why
If a datetime feature column is named
"prediction_timestamp_utc"and the prediction column is named"prediction", then"prediction" in "prediction_timestamp_utc"isTrue— so the prediction column is incorrectly classified asColumnType.Datetime, crashing any metric that runs on it.Reproduce
Fix
Add
__post_init__toColumnMapping(it's adataclass) that wraps any bare string in a one-element list for all four feature-list fields. This is called automatically by__init__so existing code using the constructor is unaffected; the fix also handles the post-construction assignment pattern (cm.datetime_features = "...") when__post_init__is called explicitly or the object is re-initialised.Testing
New test
test_column_mapping_normalizes_string_feature_listscovers:"prediction" not in ["prediction_timestamp_utc"]Noneinput preserved unchangedFixes #846