From fcfdb890027b68b2d1470b6fb7a89f9e64237891 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 17 Jul 2019 12:49:01 -0400 Subject: [PATCH 1/5] added test and copy() --- featuretools/entityset/entity.py | 2 +- .../tests/entityset_tests/test_entity.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/featuretools/entityset/entity.py b/featuretools/entityset/entity.py index 928581b522..3f78628f54 100644 --- a/featuretools/entityset/entity.py +++ b/featuretools/entityset/entity.py @@ -285,7 +285,7 @@ def _create_variables(self, variable_types, index, time_index, secondary_time_in that each map to a list of columns that depend on that secondary time """ variables = [] - variable_types = variable_types or {} + variable_types = variable_types.copy() or {} if index not in variable_types: variable_types[index] = vtypes.Index diff --git a/featuretools/tests/entityset_tests/test_entity.py b/featuretools/tests/entityset_tests/test_entity.py index c92e8b4a78..49da1dbc7f 100644 --- a/featuretools/tests/entityset_tests/test_entity.py +++ b/featuretools/tests/entityset_tests/test_entity.py @@ -127,3 +127,21 @@ def test_delete_variables(es): for var in to_delete: assert var not in variable_names assert var not in entity.df + +def test_variable_types_copy(): + df = pd.DataFrame({"id": [1, 2, 3, 4, 5, 6], + "card_id": [1, 2, 1, 3, 4, 5], + "transaction_time": [10, 12, 13, 20, 21, 20], + "fraud": [True, False, False, False, True, True]}) + + es = ft.EntitySet() + variable_types = {'fraud': ft.variable_types.Boolean} + old_variable_types = variable_types.copy() + es.entity_from_dataframe(entity_id="transactions", + dataframe=df, + index='id', + time_index='transaction_time', + variable_types=variable_types) + assert old_variable_types == variable_types + print(old_variable_types) + print(variable_types) From b879c02af644948418ddf029476641ead1a4b80a Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 17 Jul 2019 12:50:27 -0400 Subject: [PATCH 2/5] modify changelog --- docs/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 96b8df2f36..3e7f4c8bd7 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -8,6 +8,7 @@ Changelog * Fixes * Fix performance regression in DFS (:pr:`637`) * Fix deserialization of feature relationship path (:pr:`665`) + * Fix variable types modify in Entity init (:pr:`675`) * Changes * Moved dask, distributed imports (:pr:`634`) * Documentation Changes From 06e349b05f006ae40792db03155acf84d1e0927b Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 17 Jul 2019 12:51:11 -0400 Subject: [PATCH 3/5] remove print --- featuretools/tests/entityset_tests/test_entity.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/featuretools/tests/entityset_tests/test_entity.py b/featuretools/tests/entityset_tests/test_entity.py index 49da1dbc7f..c33ca50582 100644 --- a/featuretools/tests/entityset_tests/test_entity.py +++ b/featuretools/tests/entityset_tests/test_entity.py @@ -130,7 +130,6 @@ def test_delete_variables(es): def test_variable_types_copy(): df = pd.DataFrame({"id": [1, 2, 3, 4, 5, 6], - "card_id": [1, 2, 1, 3, 4, 5], "transaction_time": [10, 12, 13, 20, 21, 20], "fraud": [True, False, False, False, True, True]}) @@ -143,5 +142,3 @@ def test_variable_types_copy(): time_index='transaction_time', variable_types=variable_types) assert old_variable_types == variable_types - print(old_variable_types) - print(variable_types) From 682f0fb9a0409932a552a7bb236ced78e1a61bfd Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 17 Jul 2019 13:43:21 -0400 Subject: [PATCH 4/5] lint --- featuretools/tests/entityset_tests/test_entity.py | 1 + 1 file changed, 1 insertion(+) diff --git a/featuretools/tests/entityset_tests/test_entity.py b/featuretools/tests/entityset_tests/test_entity.py index c33ca50582..e04c0d9082 100644 --- a/featuretools/tests/entityset_tests/test_entity.py +++ b/featuretools/tests/entityset_tests/test_entity.py @@ -128,6 +128,7 @@ def test_delete_variables(es): assert var not in variable_names assert var not in entity.df + def test_variable_types_copy(): df = pd.DataFrame({"id": [1, 2, 3, 4, 5, 6], "transaction_time": [10, 12, 13, 20, 21, 20], From fb7f0973ce8906851ed2122dd649fa9fd5a50624 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 17 Jul 2019 15:19:57 -0400 Subject: [PATCH 5/5] comment fixes --- docs/source/changelog.rst | 2 +- featuretools/tests/entityset_tests/test_entity.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 3e7f4c8bd7..9fce34e071 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -8,7 +8,7 @@ Changelog * Fixes * Fix performance regression in DFS (:pr:`637`) * Fix deserialization of feature relationship path (:pr:`665`) - * Fix variable types modify in Entity init (:pr:`675`) + * Fix user-supplied variable_types modification in Entity init (:pr:`675`) * Changes * Moved dask, distributed imports (:pr:`634`) * Documentation Changes diff --git a/featuretools/tests/entityset_tests/test_entity.py b/featuretools/tests/entityset_tests/test_entity.py index e04c0d9082..fabb22c191 100644 --- a/featuretools/tests/entityset_tests/test_entity.py +++ b/featuretools/tests/entityset_tests/test_entity.py @@ -129,7 +129,7 @@ def test_delete_variables(es): assert var not in entity.df -def test_variable_types_copy(): +def test_variable_types_unmodified(): df = pd.DataFrame({"id": [1, 2, 3, 4, 5, 6], "transaction_time": [10, 12, 13, 20, 21, 20], "fraud": [True, False, False, False, True, True]})