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

improved error message for index/time_index being same column in norm… #583

Merged
merged 9 commits into from Jun 11, 2019
1 change: 1 addition & 0 deletions docs/source/changelog.rst
Expand Up @@ -10,6 +10,7 @@ Changelog
* Support custom variable types (:pr:`571`)
* Fixes
* Normalize_entity specifies error when 'make_time_index' is an invalid string (:pr:`550`)
* Improved error message for index/time_index being the same column in normalize_entity and entity_from_dataframe (:pr:`583`)
* Removed all mentions of allow_where (:pr:`587`, :pr:`588`)
* Removed unused variable in normalize entity (:pr:`589`)
* Changes
Expand Down
7 changes: 7 additions & 0 deletions featuretools/entityset/entityset.py
Expand Up @@ -646,6 +646,10 @@ def entity_from_dataframe(self,

"""
variable_types = variable_types or {}

if time_index is not None and time_index == index:
raise ValueError("time_index and index cannot be the same value, %s" % (time_index))

entity = Entity(
entity_id,
dataframe,
Expand Down Expand Up @@ -763,6 +767,9 @@ def normalize_entity(self, base_entity_id, new_entity_id, index,
new_entity_time_index = None
already_sorted = False

if new_entity_time_index is not None and new_entity_time_index == index:
alexjwang marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError("time_index and index cannot be the same value, %s" % (new_entity_time_index))

selected_variables = [index] +\
[v for v in additional_variables] +\
[v for v in copy_variables]
Expand Down
25 changes: 25 additions & 0 deletions featuretools/tests/entityset_tests/test_es.py
Expand Up @@ -982,3 +982,28 @@ def _slice_for(es, filter_eid, time_last=None):
index_eid='customers',
instances=[0],
time_last=time_last)


def test_same_index_values():
transactions_df = pd.DataFrame({"id": [1, 2, 3, 4, 5, 6],
"transaction_time": pd.date_range(start="10:00", periods=6, freq="10s"),
"first_entity_time": [1, 2, 3, 5, 6, 6]})
es = ft.EntitySet("example")

error_text = "time_index and index cannot be the same value"
with pytest.raises(ValueError, match=error_text):
es.entity_from_dataframe(entity_id="entity",
index="id",
time_index="id",
dataframe=transactions_df)

es.entity_from_dataframe(entity_id="entity",
index="id",
time_index="transaction_time",
dataframe=transactions_df)

with pytest.raises(ValueError, match=error_text):
es.normalize_entity(base_entity_id="entity",
new_entity_id="new_entity",
index="first_entity_time",
make_time_index=True)