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

Set index after adding ancestor relationship variables #668

Merged
merged 5 commits into from
Jul 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog
* Fixes
* Fix performance regression in DFS (:pr:`637`)
* Fix deserialization of feature relationship path (:pr:`665`)
* Set index after adding ancestor relationship variables (:pr:`668`)
* Fix user-supplied variable_types modification in Entity init (:pr:`675`)
* Don't calculate dependencies of unnecessary features (:pr:`667`)
* Changes
Expand Down
3 changes: 3 additions & 0 deletions featuretools/computational_backends/feature_set_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ def _add_ancestor_relationship_variables(self, child_df, parent_df,
left_on=relationship.child_variable.id,
right_on=relationship.child_variable.id)

# ensure index is maintained
df.set_index(relationship.child_entity.index, drop=False, inplace=True)

return df, new_relationship_variables

def generate_default_df(self, instance_ids, extra_columns=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,54 @@ def test_make_agg_feat_of_agg_feat(es):
assert (v == 10)


def test_make_3_stacked_agg_feats():
"""
Tests stacking 3 agg features.

The test specifically uses non numeric indices to test how ancestor variables are handled
as dataframes are merged together

"""
df = pd.DataFrame({
"id": ["a", "b", "c", "d", "e"],
"e1": ["h", "h", "i", "i", "j"],
"e2": ["x", "x", "y", "y", "x"],
"e3": ["z", "z", "z", "z", "z"],
"val": [1, 1, 1, 1, 1]
})

es = ft.EntitySet()
es.entity_from_dataframe(dataframe=df,
index="id",
entity_id="e0")

es.normalize_entity(base_entity_id="e0",
new_entity_id="e1",
index="e1",
additional_variables=["e2", "e3"])

es.normalize_entity(base_entity_id="e1",
new_entity_id="e2",
index="e2",
additional_variables=["e3"])

es.normalize_entity(base_entity_id="e2",
new_entity_id="e3",
index="e3")

sum_1 = ft.Feature(es["e0"]["val"], parent_entity=es["e1"], primitive=Sum)
sum_2 = ft.Feature(sum_1, parent_entity=es["e2"], primitive=Sum)
sum_3 = ft.Feature(sum_2, parent_entity=es["e3"], primitive=Sum)

feature_set = FeatureSet([sum_3])
calculator = FeatureSetCalculator(es,
time_last=None,
feature_set=feature_set)
df = calculator.run(np.array(["z"]))
v = df[sum_3.get_name()][0]
assert (v == 5)


def test_make_dfeat_of_agg_feat_on_self(es):
"""
The graph looks like this:
Expand Down