From d9cfe2df9ebf701a906878ae5cd6975b606cc4e7 Mon Sep 17 00:00:00 2001 From: christopherbunn Date: Tue, 3 Sep 2019 16:21:11 -0400 Subject: [PATCH 1/9] Added check for time_index and tests --- docs/source/changelog.rst | 1 + featuretools/entityset/entityset.py | 3 +++ featuretools/tests/entityset_tests/test_es.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 82107be902..78668bd17f 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -7,6 +7,7 @@ Changelog * Improve how files are copied and written (:pr:`721`) * Fixes * Fixed entity set deserialization (:pr:`720`) + * Added error message when DatetimeTimeIndex is not set as time_index (:pr:`497`) * Changes * Documentation Changes * Updated URL for Compose (:pr:`716`) diff --git a/featuretools/entityset/entityset.py b/featuretools/entityset/entityset.py index e5b83a46eb..8bace14c32 100644 --- a/featuretools/entityset/entityset.py +++ b/featuretools/entityset/entityset.py @@ -485,6 +485,9 @@ def entity_from_dataframe(self, if time_index is not None and time_index == index: raise ValueError("time_index and index cannot be the same value, %s" % (time_index)) + if vtypes.DatetimeTimeIndex in variable_types.values() and time_index is None: + raise ValueError("'DatetimeTimeIndex' must be set using time_index parameter") + entity = Entity( entity_id, dataframe, diff --git a/featuretools/tests/entityset_tests/test_es.py b/featuretools/tests/entityset_tests/test_es.py index 38c9d28f17..84ce8a1936 100644 --- a/featuretools/tests/entityset_tests/test_es.py +++ b/featuretools/tests/entityset_tests/test_es.py @@ -945,3 +945,20 @@ def test_same_index_values(): new_entity_id="new_entity", index="first_entity_time", make_time_index=True) + + +def test_use_time_index(): + df = pd.DataFrame({"id": [1, 2, 3, 4, 5, 6], + "transaction_time": pd.date_range(start="10:00", periods=6, freq="10s")}) + es = ft.EntitySet() + error_text = "'DatetimeTimeIndex' must be set using time_index parameter" + with pytest.raises(ValueError, match=error_text): + es.entity_from_dataframe(entity_id="entity", + index="id", + variable_types={"transaction_time": variable_types.DatetimeTimeIndex}, + dataframe=df) + + es.entity_from_dataframe(entity_id="entity", + index="id", + time_index="transaction_time", + dataframe=df) From 67cae72dcddef4becf8ed68cd87d8fbfc5549c2d Mon Sep 17 00:00:00 2001 From: christopherbunn Date: Tue, 3 Sep 2019 16:26:32 -0400 Subject: [PATCH 2/9] Removed changelong pull request number --- docs/source/changelog.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 78668bd17f..82107be902 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -7,7 +7,6 @@ Changelog * Improve how files are copied and written (:pr:`721`) * Fixes * Fixed entity set deserialization (:pr:`720`) - * Added error message when DatetimeTimeIndex is not set as time_index (:pr:`497`) * Changes * Documentation Changes * Updated URL for Compose (:pr:`716`) From f44b62a6dbd3fea118bc5122ea4f2cadc1350af7 Mon Sep 17 00:00:00 2001 From: christopherbunn Date: Tue, 3 Sep 2019 16:46:06 -0400 Subject: [PATCH 3/9] Updated changelog with PR number --- docs/source/changelog.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 82107be902..e1fd3c0377 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -7,13 +7,14 @@ Changelog * Improve how files are copied and written (:pr:`721`) * Fixes * Fixed entity set deserialization (:pr:`720`) + * Added error message when DateTimeIndex is a variable but not set as the time_index (:pr:`497`) * Changes * Documentation Changes * Updated URL for Compose (:pr:`716`) * Testing Changes Thanks to the following people for contributing to this release: - :user:`jeff-hernandez` + :user:`jeff-hernandez`, :user:`christopherbunn` **v0.10.1 Aug 25, 2019** From a89be29c3e845e4144a44275b952808966d2d764 Mon Sep 17 00:00:00 2001 From: christopherbunn Date: Tue, 3 Sep 2019 16:50:35 -0400 Subject: [PATCH 4/9] Corrected PR number in changelog --- docs/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index e1fd3c0377..52677992b2 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -7,7 +7,7 @@ Changelog * Improve how files are copied and written (:pr:`721`) * Fixes * Fixed entity set deserialization (:pr:`720`) - * Added error message when DateTimeIndex is a variable but not set as the time_index (:pr:`497`) + * Added error message when DateTimeIndex is a variable but not set as the time_index (:pr:`723`) * Changes * Documentation Changes * Updated URL for Compose (:pr:`716`) From 13e6a27d78a2090308078b01979a0b5790e7b240 Mon Sep 17 00:00:00 2001 From: christopherbunn Date: Tue, 3 Sep 2019 17:27:25 -0400 Subject: [PATCH 5/9] Updated error message to include variable name --- featuretools/entityset/entityset.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/featuretools/entityset/entityset.py b/featuretools/entityset/entityset.py index 8bace14c32..0968446c70 100644 --- a/featuretools/entityset/entityset.py +++ b/featuretools/entityset/entityset.py @@ -486,7 +486,8 @@ def entity_from_dataframe(self, raise ValueError("time_index and index cannot be the same value, %s" % (time_index)) if vtypes.DatetimeTimeIndex in variable_types.values() and time_index is None: - raise ValueError("'DatetimeTimeIndex' must be set using time_index parameter") + var_name = variable_types.keys()[variable_types.values().index(vtypes.DatetimeTimeIndex)] + raise ValueError("Variable %s must be set using time_index parameter" % (var_name)) entity = Entity( entity_id, From 4d2bb64d0f98d28899511e0590623f5a2096ade6 Mon Sep 17 00:00:00 2001 From: christopherbunn Date: Tue, 3 Sep 2019 17:28:38 -0400 Subject: [PATCH 6/9] Moved changelog names --- docs/source/changelog.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 52677992b2..76db82e45c 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -14,7 +14,7 @@ Changelog * Testing Changes Thanks to the following people for contributing to this release: - :user:`jeff-hernandez`, :user:`christopherbunn` + :user:`jeff-hernandez`, :user:`christopherbunn`, :user:`kmax12` **v0.10.1 Aug 25, 2019** @@ -24,7 +24,7 @@ Changelog * Fixed FAQ cell output (:pr:`710`) Thanks to the following people for contributing to this release: - :user:`gsheni`, :user:`kmax12`, :user:`rwedge` + :user:`gsheni`, :user:`rwedge` **v0.10.0 Aug 19, 2019** From f27d1de3574d39200758ba05ca847fd065e9c4c7 Mon Sep 17 00:00:00 2001 From: christopherbunn Date: Tue, 3 Sep 2019 17:48:42 -0400 Subject: [PATCH 7/9] Cleaned up method used to find variable name --- featuretools/entityset/entityset.py | 7 ++++--- featuretools/tests/entityset_tests/test_es.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/featuretools/entityset/entityset.py b/featuretools/entityset/entityset.py index 0968446c70..1b3873af57 100644 --- a/featuretools/entityset/entityset.py +++ b/featuretools/entityset/entityset.py @@ -485,9 +485,10 @@ def entity_from_dataframe(self, if time_index is not None and time_index == index: raise ValueError("time_index and index cannot be the same value, %s" % (time_index)) - if vtypes.DatetimeTimeIndex in variable_types.values() and time_index is None: - var_name = variable_types.keys()[variable_types.values().index(vtypes.DatetimeTimeIndex)] - raise ValueError("Variable %s must be set using time_index parameter" % (var_name)) + if time_index is None: + for variable, variable_type in variable_types.items(): + if variable_type == vtypes.DatetimeTimeIndex: + raise ValueError("Variable %s must be set using time_index parameter" % (variable)) entity = Entity( entity_id, diff --git a/featuretools/tests/entityset_tests/test_es.py b/featuretools/tests/entityset_tests/test_es.py index 84ce8a1936..2f700d8aed 100644 --- a/featuretools/tests/entityset_tests/test_es.py +++ b/featuretools/tests/entityset_tests/test_es.py @@ -951,7 +951,7 @@ def test_use_time_index(): df = pd.DataFrame({"id": [1, 2, 3, 4, 5, 6], "transaction_time": pd.date_range(start="10:00", periods=6, freq="10s")}) es = ft.EntitySet() - error_text = "'DatetimeTimeIndex' must be set using time_index parameter" + error_text = "Variable transaction_time must be set using time_index parameter" with pytest.raises(ValueError, match=error_text): es.entity_from_dataframe(entity_id="entity", index="id", From 87bab7d330ccbcb971f6345599acfe28a3686296 Mon Sep 17 00:00:00 2001 From: christopherbunn Date: Tue, 3 Sep 2019 17:55:46 -0400 Subject: [PATCH 8/9] Updated error message to clarify variable type --- featuretools/entityset/entityset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/featuretools/entityset/entityset.py b/featuretools/entityset/entityset.py index 1b3873af57..a7d371fc4e 100644 --- a/featuretools/entityset/entityset.py +++ b/featuretools/entityset/entityset.py @@ -488,7 +488,7 @@ def entity_from_dataframe(self, if time_index is None: for variable, variable_type in variable_types.items(): if variable_type == vtypes.DatetimeTimeIndex: - raise ValueError("Variable %s must be set using time_index parameter" % (variable)) + raise ValueError("DatetimeTimeIndex variable %s must be set using time_index parameter" % (variable)) entity = Entity( entity_id, From 819153129f705f4ce16bf999e996ce79704077f3 Mon Sep 17 00:00:00 2001 From: christopherbunn Date: Tue, 3 Sep 2019 18:02:59 -0400 Subject: [PATCH 9/9] Updated tests to reflect new error message --- featuretools/tests/entityset_tests/test_es.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/featuretools/tests/entityset_tests/test_es.py b/featuretools/tests/entityset_tests/test_es.py index 2f700d8aed..b21455dcd7 100644 --- a/featuretools/tests/entityset_tests/test_es.py +++ b/featuretools/tests/entityset_tests/test_es.py @@ -951,7 +951,7 @@ def test_use_time_index(): df = pd.DataFrame({"id": [1, 2, 3, 4, 5, 6], "transaction_time": pd.date_range(start="10:00", periods=6, freq="10s")}) es = ft.EntitySet() - error_text = "Variable transaction_time must be set using time_index parameter" + error_text = "DatetimeTimeIndex variable transaction_time must be set using time_index parameter" with pytest.raises(ValueError, match=error_text): es.entity_from_dataframe(entity_id="entity", index="id",