Skip to content

Commit

Permalink
22132: Fixes bug where bounds aren't getting set for nominal features…
Browse files Browse the repository at this point in the history
… in IFA (#324)
  • Loading branch information
apbassett authored Nov 8, 2024
1 parent dc21437 commit 65a3c62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
22 changes: 10 additions & 12 deletions howso/utilities/feature_attributes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ def _process(self, # noqa: C901
DeprecationWarning)
else:
self.attributes = FeatureAttributesBase({})
features = dict()

if datetime_feature_formats is None:
datetime_feature_formats = dict()
Expand Down Expand Up @@ -671,7 +672,7 @@ def _process(self, # noqa: C901
# datetime_feature_formats is expected to either be only a
# single string (format) or a tuple of strings (format, locale)
user_dt_format = datetime_feature_formats[feature_name]
if features and 'date_time_format' in features.get(feature_name, {}):
if 'date_time_format' in features.get(feature_name, {}):
warnings.warn(f'Warning: date_time_format for {feature_name} '
'provided in both `features` (ignored) and '
'`datetime_feature_formats`.')
Expand Down Expand Up @@ -789,7 +790,7 @@ def _process(self, # noqa: C901
# DECLARED DEPENDENTS
# First determine if there are any dependent features in the partial features dict
partial_dependent_features = []
if features and 'dependent_features' in features.get(feature_name, {}):
if 'dependent_features' in features.get(feature_name, {}):
partial_dependent_features = features[feature_name]['dependent_features']
# Set dependent features: `dependent_features` + partial features dict, if provided
if feature_name in dependent_features:
Expand All @@ -807,23 +808,20 @@ def _process(self, # noqa: C901
f'not {type(id_feature_name)}.')

if infer_bounds:
for feature_name in self.attributes:
# Don't infer bounds for manually-specified nominal features
if self.attributes[feature_name].get('type') == 'nominal':
continue
# Likewise, don't infer bounds for JSON/YAML features
elif any([
self.attributes[feature_name].get('data_type') in ['json', 'yaml'],
features and features.get(feature_name, {}).get('data_type') in ['json', 'yaml']
]):
for feature_name, _attributes in self.attributes.items():
# Don't infer bounds for JSON/YAML features
if (
_attributes.get('data_type') in ['json', 'yaml'] or
features.get(feature_name, {}).get('data_type') in ['json', 'yaml']
):
continue
bounds = self._infer_feature_bounds(
self.attributes, feature_name,
tight_bounds=tight_bounds,
mode_bound_features=mode_bound_features,
)
if bounds:
self.attributes[feature_name]['bounds'] = bounds # noqa
_attributes['bounds'] = bounds # noqa

# Do any features contain data unsupported by the core?
self._check_unsupported_data(self.attributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,12 @@ def test_preset_feature_types(data, types, expected_types, is_valid):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
if is_valid:
features = infer_feature_attributes(data, types=types)
features = infer_feature_attributes(data, types=types, )
for feature_name, expected_type in expected_types.items():
# Make sure it is the correct type
assert features[feature_name]['type'] == expected_type
# All features in this test, including nominals, should have bounds (at the very least: `allow_null`)
assert 'allow_null' in features[feature_name].get('bounds', {}).keys()
else:
with pytest.raises(ValueError):
infer_feature_attributes(data, types=types)

0 comments on commit 65a3c62

Please sign in to comment.