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

Add __eq__ for ComponentBase+PipelineBase #1178

Merged
merged 16 commits into from Sep 17, 2020
Merged

Add __eq__ for ComponentBase+PipelineBase #1178

merged 16 commits into from Sep 17, 2020

Conversation

angela97lin
Copy link
Contributor

@angela97lin angela97lin commented Sep 15, 2020

Closes #475.

@angela97lin angela97lin self-assigned this Sep 15, 2020
@codecov
Copy link

codecov bot commented Sep 15, 2020

Codecov Report

Merging #1178 into main will increase coverage by 0.18%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1178      +/-   ##
==========================================
+ Coverage   99.73%   99.92%   +0.18%     
==========================================
  Files         196      196              
  Lines       11813    11977     +164     
==========================================
+ Hits        11782    11968     +186     
+ Misses         31        9      -22     
Impacted Files Coverage Δ
evalml/pipelines/components/component_base.py 100.00% <100.00%> (ø)
...valml/pipelines/components/estimators/estimator.py 100.00% <100.00%> (ø)
evalml/pipelines/pipeline_base.py 100.00% <100.00%> (ø)
evalml/tests/component_tests/test_components.py 100.00% <100.00%> (+0.74%) ⬆️
evalml/tests/component_tests/test_estimators.py 100.00% <100.00%> (ø)
...alml/tests/component_tests/test_lgbm_classifier.py 100.00% <100.00%> (ø)
evalml/tests/pipeline_tests/test_pipelines.py 100.00% <100.00%> (+0.85%) ⬆️
evalml/tests/utils_tests/test_gen_utils.py 100.00% <100.00%> (ø)
evalml/utils/__init__.py 100.00% <100.00%> (ø)
evalml/utils/gen_utils.py 99.02% <100.00%> (+2.18%) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7cf63a7...a0e5be2. Read the comment docs.

@angela97lin angela97lin marked this pull request as ready for review Sep 16, 2020
@angela97lin angela97lin added this to the September 2020 milestone Sep 16, 2020
Copy link
Collaborator

@dsherry dsherry left a comment

@angela97lin LGTM! My only blocking comment was about not checking the class attributes during comparison, only instance attributes.

evalml/pipelines/components/component_base.py Outdated Show resolved Hide resolved
evalml/utils/gen_utils.py Show resolved Hide resolved
evalml/pipelines/pipeline_base.py Outdated Show resolved Hide resolved
evalml/pipelines/components/component_base.py Show resolved Hide resolved
evalml/tests/utils_tests/test_gen_utils.py Show resolved Hide resolved
evalml/tests/utils_tests/test_gen_utils.py Show resolved Hide resolved
evalml/tests/pipeline_tests/test_pipelines.py Show resolved Hide resolved
evalml/tests/pipeline_tests/test_pipelines.py Outdated Show resolved Hide resolved
evalml/tests/pipeline_tests/test_pipelines.py Show resolved Hide resolved
Copy link
Contributor

@freddyaboulton freddyaboulton left a comment

@angela97lin I think this is great! I think the tests are pretty extensive and the implementation is cool. My only comment is that I think it would be good to write a test to check __eq__ for all currently and future defined components using pytest parametrize and all_components(). This would automatically test all components as they're added which would help us catch breaking changes as they're added.

evalml/pipelines/components/component_base.py Show resolved Hide resolved
evalml/pipelines/pipeline_base.py Show resolved Hide resolved
@@ -781,3 +781,62 @@ def test_estimators_accept_all_kwargs(estimator_class):
# Deleting because we call it random_state in our api
del params["random_seed"]
estimator_class(**params)

Copy link
Contributor

@freddyaboulton freddyaboulton Sep 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to check that all of our components are equal with themselves and not equal with the same component class with different parameters just to safeguard against future refactorings of our api and automatically check that new parameters don't break __eq__

@pytest.mark.parametrize("component_class", all_components())
def test_equality_all_defined_components(component_class):
    assert component_class() == component_class()
    kwargs = {"foo": 1, "bar": 2}
    assert component_class(**kwargs) != component_class()

Copy link
Contributor Author

@angela97lin angela97lin Sep 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oo sure, looks like I had to do the same mocking set up in test_components_init_kwargs to pass in kwargs that won't break, so I'm going to add two lines there rather than duplicate the mocking in a separate test. I added the assert component_class() == component_class() tests for all components too.

evalml/pipelines/pipeline_base.py Show resolved Hide resolved
@angela97lin angela97lin merged commit 570cd24 into main Sep 17, 2020
@angela97lin angela97lin deleted the 475_equality branch Sep 17, 2020
This was referenced Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add __eq__ for ComponentBase+PipelineBase
3 participants