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

Specifies error when 'make_time_index' is an invalid string (#537) #550

Merged
merged 8 commits into from
May 21, 2019
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
7 changes: 7 additions & 0 deletions featuretools/entityset/entityset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from featuretools.entityset import deserialize, serialize
from featuretools.entityset.entity import Entity
from featuretools.entityset.relationship import Relationship
from featuretools.utils import is_string
from featuretools.utils.gen_utils import make_tqdm_iterator

pd.options.mode.chained_assignment = None # default='warn'
Expand Down Expand Up @@ -714,6 +715,12 @@ def normalize_entity(self, base_entity_id, new_entity_id, index,
if v == index:
raise ValueError("Not copying {} as both index and variable".format(v))
break
gsheni marked this conversation as resolved.
Show resolved Hide resolved
if is_string(make_time_index):
if make_time_index not in base_entity.df.columns:
raise ValueError("'make_time_index' must be a variable in the base entity")
elif make_time_index not in additional_variables + copy_variables:
raise ValueError("'make_time_index' must specified in 'additional_variables' or 'copy_variables'")

new_index = index

transfer_types = {}
Expand Down
14 changes: 13 additions & 1 deletion featuretools/tests/entityset_tests/test_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,16 @@ def test_normalize_entity(es):
es.normalize_entity('sessions', 'device_types', 'device_type',
copy_variables='log')

error_text = "'make_time_index' must be a variable in the base entity"
with pytest.raises(ValueError, match=error_text):
es.normalize_entity('sessions', 'device_types', 'device_type',
make_time_index="nonextistent")

error_text = "'make_time_index' must specified in 'additional_variables' or 'copy_variables'"
with pytest.raises(ValueError, match=error_text):
es.normalize_entity('sessions', 'device_types', 'device_type',
make_time_index='ip')

es.normalize_entity('sessions', 'device_types', 'device_type',
additional_variables=['device_name'],
make_time_index=False)
Expand All @@ -828,7 +838,9 @@ def test_normalize_entity(es):

def test_normalize_time_index_from_none(es):
es['customers'].time_index = None
es.normalize_entity('customers', 'birthdays', 'date_of_birth', make_time_index='date_of_birth')
es.normalize_entity('customers', 'birthdays', 'age',
make_time_index='date_of_birth',
copy_variables=['date_of_birth'])
assert es['birthdays'].time_index == 'date_of_birth'
assert es['birthdays'].df['date_of_birth'].is_monotonic_increasing

Expand Down