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

fixed hash issue with same base features #8

Merged
merged 3 commits into from Oct 11, 2017
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
4 changes: 3 additions & 1 deletion featuretools/primitives/binary_transform.py
Expand Up @@ -24,7 +24,9 @@ def __init__(self, left, right):

self._right_index = -1
if isinstance(right, PrimitiveBase):
base_features.append(right)
if (not isinstance(left, PrimitiveBase) or
right.hash() != self.left.hash()):
base_features.append(right)
self.right = right
else:
self.right = right
Expand Down
10 changes: 10 additions & 0 deletions featuretools/tests/computational_backend/test_pandas_backend.py
Expand Up @@ -444,3 +444,13 @@ def test_topn(entityset, backend):
for i, values in enumerate(df[topn.get_name()].values):
for j, v in enumerate(values):
assert (v == true_results[i][j])


def test_direct_squared(entityset, backend):
feature = IdentityFeature(entityset['log']['value'])
squared = feature * feature
pandas_backend = backend([feature, squared])
df = pandas_backend.calculate_all_features(instance_ids=[0, 1, 2],
time_last=None)
for i, row in df.iterrows():
assert (row[0] * row[0]) == row[1]
Expand Up @@ -39,4 +39,4 @@ def test_direct_rename(es):
assert feat.hash() != copy_feat.hash()
assert feat.get_name() != copy_feat.get_name()
assert feat.base_features[0]._get_name() == copy_feat.base_features[0]._get_name()
assert feat.entity == copy_feat.entity
assert feat.entity == copy_feat.entity
Expand Up @@ -70,3 +70,10 @@ def test_get_depth(es):
assert d2.get_depth(stop_at=[f, g, agg2]) == 2
assert d2.get_depth(stop_at=[f, g, d1]) == 1
assert d2.get_depth(stop_at=[f, g, d2]) == 0


def test_squared(es):
feature = Feature(es['log']['value'])
squared = feature * feature
assert len(squared.base_features) == 1
assert squared.base_features[0].hash() == feature.hash()