-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Figure select function selector #2844
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c73aef
select_traces selector argument can now be a function
nicholas-esterer 7040a57
Merge branch 'master' into select-traces-function-selector
nicholas-esterer b492497
Instead allow _selector_matches to accept function selector
nicholas-esterer 4b3bd27
select_traces uses _selector_matches accepting function
nicholas-esterer c4423ef
BaseFigure._selector_matches accepts function selector
nicholas-esterer 663b062
Update _selector_matches error
nicholas-esterer 9de2946
changelog entry
nicholas-esterer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/python/plotly/plotly/tests/test_core/test_update_objects/test_selector_matches.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import pytest | ||
|
||
import plotly.graph_objects as go | ||
from plotly.basedatatypes import BaseFigure | ||
|
||
|
||
def test_selector_none(): | ||
# should return True | ||
assert BaseFigure._selector_matches({}, None) == True # arbitrary, | ||
|
||
|
||
def test_selector_empty_dict(): | ||
# should return True | ||
assert ( | ||
BaseFigure._selector_matches(dict(hello="everybody"), {}) == True # arbitrary, | ||
) | ||
|
||
|
||
def test_selector_matches_subset_of_obj(): | ||
# should return True | ||
assert ( | ||
BaseFigure._selector_matches( | ||
dict(hello="everybody", today="cloudy", myiq=55), | ||
dict(myiq=55, today="cloudy"), | ||
) | ||
== True | ||
) | ||
|
||
|
||
def test_selector_has_nonmatching_key(): | ||
# should return False | ||
assert ( | ||
BaseFigure._selector_matches( | ||
dict(hello="everybody", today="cloudy", myiq=55), | ||
dict(myiq=55, cronenberg="scanners"), | ||
) | ||
== False | ||
) | ||
|
||
|
||
def test_selector_has_nonmatching_value(): | ||
# should return False | ||
assert ( | ||
BaseFigure._selector_matches( | ||
dict(hello="everybody", today="cloudy", myiq=55), | ||
dict(myiq=55, today="sunny"), | ||
) | ||
== False | ||
) | ||
|
||
|
||
def test_baseplotlytypes_could_match(): | ||
# should return True | ||
obj = go.layout.Annotation(x=1, y=2, text="pat metheny") | ||
sel = go.layout.Annotation(x=1, y=2, text="pat metheny") | ||
assert BaseFigure._selector_matches(obj, sel) == True | ||
|
||
|
||
def test_baseplotlytypes_could_not_match(): | ||
# should return False | ||
obj = go.layout.Annotation(x=1, y=3, text="pat metheny") | ||
sel = go.layout.Annotation(x=1, y=2, text="pat metheny") | ||
assert BaseFigure._selector_matches(obj, sel) == False | ||
|
||
|
||
def test_baseplotlytypes_cannot_match_subset(): | ||
# should return False because "undefined" keys in sel return None, and are | ||
# compared (because "key in sel" returned True, it's value was None) | ||
obj = go.layout.Annotation(x=1, y=2, text="pat metheny") | ||
sel = go.layout.Annotation(x=1, y=2,) | ||
assert BaseFigure._selector_matches(obj, sel) == False | ||
|
||
|
||
def test_function_selector_could_match(): | ||
# should return True | ||
obj = go.layout.Annotation(x=1, y=2, text="pat metheny") | ||
|
||
def _sel(d): | ||
return d["x"] == 1 and d["y"] == 2 and d["text"] == "pat metheny" | ||
|
||
assert BaseFigure._selector_matches(obj, _sel) == True | ||
|
||
|
||
def test_function_selector_could_not_match(): | ||
# should return False | ||
obj = go.layout.Annotation(x=1, y=2, text="pat metheny") | ||
|
||
def _sel(d): | ||
return d["x"] == 1 and d["y"] == 3 and d["text"] == "pat metheny" | ||
|
||
assert BaseFigure._selector_matches(obj, _sel) == False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is now more than just "a trace" right? maybe "a graph object" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, copy paste error! good catch 👍