-
Notifications
You must be signed in to change notification settings - Fork 26
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
Update update_transformers
validation
#563
Changes from 1 commit
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
import pandas as pd | ||
import yaml | ||
|
||
from rdt.errors import Error, NotFittedError | ||
from rdt.errors import Error, InvalidSdtypeForTransformerError, NotFittedError | ||
from rdt.transformers import ( | ||
BaseTransformer, get_class_by_transformer_name, get_default_transformer, | ||
get_transformer_instance, get_transformers_by_type) | ||
|
@@ -442,21 +442,17 @@ def update_transformers(self, column_name_to_transformer): | |
self._validate_update_columns(update_columns) | ||
self._validate_transformers(column_name_to_transformer) | ||
|
||
incompatible_sdtypes = [] | ||
for column_name, transformer in column_name_to_transformer.items(): | ||
if transformer is not None: | ||
current_sdtype = self.field_sdtypes.get(column_name) | ||
if current_sdtype and current_sdtype not in transformer.get_supported_sdtypes(): | ||
incompatible_sdtypes.append(column_name) | ||
raise InvalidSdtypeForTransformerError( | ||
f"Column '{column_name}' is a {current_sdtype} column, which is " | ||
f"incompatible with the '{type(transformer).__name__}' transformer." | ||
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. 🤔 Should we add a |
||
) | ||
|
||
self.field_transformers[column_name] = transformer | ||
|
||
if incompatible_sdtypes: | ||
warnings.warn( | ||
"Some transformers you've assigned are not compatible with the sdtypes. " | ||
f"Use 'update_sdtypes' to update: {incompatible_sdtypes}" | ||
) | ||
|
||
self._modified_config = True | ||
|
||
def remove_transformers(self, column_names): | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ | |||||||||||
import pytest | ||||||||||||
|
||||||||||||
from rdt import HyperTransformer | ||||||||||||
from rdt.errors import InvalidSdtypeForTransformerError | ||||||||||||
from rdt.performance.datasets import BaseDatasetGenerator | ||||||||||||
from rdt.transformers import BaseTransformer | ||||||||||||
|
||||||||||||
|
@@ -255,7 +256,11 @@ def _test_transformer_with_hypertransformer(transformer_class, input_data, steps | |||||||||||
} | ||||||||||||
|
||||||||||||
hypertransformer.detect_initial_config(input_data) | ||||||||||||
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. you can just delete this line now. You only need to detect if you don't set it |
||||||||||||
hypertransformer.update_transformers(field_transformers) | ||||||||||||
try: | ||||||||||||
hypertransformer.update_transformers(field_transformers) | ||||||||||||
except InvalidSdtypeForTransformerError: | ||||||||||||
pass | ||||||||||||
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 instead we could use the 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. It will still run into an error, since we have a version of it validating set_config as well: Lines 240 to 244 in 1c2c821
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. When we set the config can't we force the sdtype to match? |
||||||||||||
|
||||||||||||
hypertransformer.fit(input_data) | ||||||||||||
|
||||||||||||
transformed = hypertransformer.transform(input_data) | ||||||||||||
|
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.
I think we should change this error name to match the ones we created in the doc. You won't need to catch this error anymore in the integration tests if you do the other change