Skip to content

Commit

Permalink
Check argument types for .normalize_entity (#195)
Browse files Browse the repository at this point in the history
* Check argument types for .normali_entity

* Fix logic order

* Separate two cases and give more verbose messages

* Added test for additional_variables and copy_variables desired behaviors

* Fix style issue
  • Loading branch information
Xinbin Huang authored and kmax12 committed Jul 24, 2018
1 parent bdcd663 commit ee25b59
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions featuretools/entityset/entityset.py
Expand Up @@ -800,6 +800,15 @@ def normalize_entity(self, base_entity_id, new_entity_id, index,
# variable_types = base_entity.variable_types
additional_variables = additional_variables or []
copy_variables = copy_variables or []

if not isinstance(additional_variables, list):
raise TypeError("'additional_variables' must be a list, but received type {}"
.format(type(additional_variables)))

if not isinstance(copy_variables, list):
raise TypeError("'copy_variables' must be a list, but received type {}"
.format(type(copy_variables)))

for v in additional_variables + copy_variables:
if v == index:
raise ValueError("Not copying {} as both index and variable".format(v))
Expand Down
8 changes: 8 additions & 0 deletions featuretools/tests/entityset_tests/test_es.py
Expand Up @@ -731,6 +731,14 @@ def test_add_link_vars(entityset):


def test_normalize_entity(entityset):
with pytest.raises(TypeError):
entityset.normalize_entity('sessions', 'device_types', 'device_type',
additional_variables='log')

with pytest.raises(TypeError):
entityset.normalize_entity('sessions', 'device_types', 'device_type',
copy_variables='log')

entityset.normalize_entity('sessions', 'device_types', 'device_type',
additional_variables=['device_name'],
make_time_index=False)
Expand Down

0 comments on commit ee25b59

Please sign in to comment.