Skip to content
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

Better handle empty fields with distinct_values=[] #1574

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ludwig/automl/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ def infer_type(
:return: (str) feature type
"""
num_distinct_values = field.num_distinct_values
if num_distinct_values == 0:
return CATEGORY
distinct_values = field.distinct_values
if num_distinct_values <= 2 and missing_value_percent == 0:
# Check that all distinct values are conventional bools.
Expand Down Expand Up @@ -385,6 +387,9 @@ def should_exclude(idx: int, field: FieldInfo, dtype: str, row_count: int, targe
if field.name in targets:
return False

if field.num_distinct_values == 0:
return True

distinct_value_percent = float(field.num_distinct_values) / row_count
if distinct_value_percent == 1.0:
upper_name = field.name.upper()
Expand Down
2 changes: 2 additions & 0 deletions tests/ludwig/automl/test_base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
(2, ['1.5', '3.7'], 0, 0, 0.1, NUMERICAL),
(ROW_COUNT, [], 3, 0, 0.0, TEXT),
(ROW_COUNT, [], 1, ROW_COUNT, 0.0, IMAGE),
(0, [], 0, 0, 0.0, CATEGORY),
])
def test_infer_type(num_distinct_values, distinct_values, avg_words, img_values, missing_vals, expected):
field = FieldInfo(
Expand All @@ -36,6 +37,7 @@ def test_infer_type(num_distinct_values, distinct_values, avg_words, img_values,
(0, ROW_COUNT, TEXT, 'name', False),
(0, ROW_COUNT, NUMERICAL, TARGET_NAME, False),
(0, ROW_COUNT - 1, NUMERICAL, 'id', False),
(0, 0, CATEGORY, 'empty_col', True),
])
def test_should_exclude(idx, num_distinct_values, dtype, name, expected):
field = FieldInfo(
Expand Down