From d0ebff1073d658ddc87d334b3051038cc4bc7f45 Mon Sep 17 00:00:00 2001 From: George Wambold Date: Fri, 14 Dec 2018 10:39:01 -0600 Subject: [PATCH] Add specific error for duplicate additional/copy_variables in normalize_entity (#348) --- featuretools/entityset/entityset.py | 6 ++++++ featuretools/tests/entityset_tests/test_es.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/featuretools/entityset/entityset.py b/featuretools/entityset/entityset.py index 31b622202a..35aca22908 100644 --- a/featuretools/entityset/entityset.py +++ b/featuretools/entityset/entityset.py @@ -753,10 +753,16 @@ def normalize_entity(self, base_entity_id, new_entity_id, index, raise TypeError("'additional_variables' must be a list, but received type {}" .format(type(additional_variables))) + if len(additional_variables) != len(set(additional_variables)): + raise ValueError("'additional_variables' contains duplicate variables. All variables must be unique.") + if not isinstance(copy_variables, list): raise TypeError("'copy_variables' must be a list, but received type {}" .format(type(copy_variables))) + if len(copy_variables) != len(set(copy_variables)): + raise ValueError("'copy_variables' contains duplicate variables. All variables must be unique.") + for v in additional_variables + copy_variables: if v == index: raise ValueError("Not copying {} as both index and variable".format(v)) diff --git a/featuretools/tests/entityset_tests/test_es.py b/featuretools/tests/entityset_tests/test_es.py index 5a1086d91c..55ce356c47 100644 --- a/featuretools/tests/entityset_tests/test_es.py +++ b/featuretools/tests/entityset_tests/test_es.py @@ -843,6 +843,20 @@ def test_normalize_time_index_from_none(entityset): assert entityset['birthdays'].time_index == 'date_of_birth' +def test_raise_error_if_dupicate_additional_variables_passed(entityset): + error_text = "'additional_variables' contains duplicate variables. All variables must be unique." + with pytest.raises(ValueError, match=error_text): + entityset.normalize_entity('sessions', 'device_types', 'device_type', + additional_variables=['device_name', 'device_name']) + + +def test_raise_error_if_dupicate_copy_variables_passed(entityset): + error_text = "'copy_variables' contains duplicate variables. All variables must be unique." + with pytest.raises(ValueError, match=error_text): + entityset.normalize_entity('sessions', 'device_types', 'device_type', + copy_variables=['device_name', 'device_name']) + + def test_normalize_entity_copies_variable_types(entityset): entityset['log'].convert_variable_type( 'value', variable_types.Ordinal, convert_data=False)