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

Using a dictionary as a value of 'labels','breaks','values' in scales #947

Merged
merged 27 commits into from
Nov 30, 2023
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f22f5a8
Add support of dict for scale `labels` parameter.
OLarionova-HORIS Nov 10, 2023
80b5fdb
Add dict for scale `breaks` parameter.
OLarionova-HORIS Nov 10, 2023
718857b
Add test demo notebook.
OLarionova-HORIS Nov 10, 2023
2de3f69
Scale 'values' as dict of breaks to values.
OLarionova-HORIS Nov 13, 2023
b8dec2a
Cleanup code. Add new examples.
OLarionova-HORIS Nov 13, 2023
effcc18
Prohibit simultaneous use of labels/value-dictionary and breaks-list.
OLarionova-HORIS Nov 14, 2023
28a6b5a
* labels-dict + breaks-list => combining
OLarionova-HORIS Nov 16, 2023
f012496
Update notebook.
OLarionova-HORIS Nov 16, 2023
a7b937d
labels-dict: remove missing breaks from labels, empty string for miss…
OLarionova-HORIS Nov 17, 2023
2f6bff2
'breaks': move breaks without label to the tail.
OLarionova-HORIS Nov 21, 2023
0a0d454
Add demo notebook.
OLarionova-HORIS Nov 21, 2023
9520be2
Fix docstrings.
OLarionova-HORIS Nov 21, 2023
d6e4b5a
Add tests.
OLarionova-HORIS Nov 22, 2023
aa5c565
Improve python code.
OLarionova-HORIS Nov 22, 2023
1e30bae
Update notebook.
OLarionova-HORIS Nov 22, 2023
d82a523
Minor code improve.
OLarionova-HORIS Nov 22, 2023
13a72ce
Remove test notebook.
OLarionova-HORIS Nov 22, 2023
05a91d0
Update future_changes.md.
OLarionova-HORIS Nov 22, 2023
2327b4e
Add support of 'breaks'-dict.
OLarionova-HORIS Nov 23, 2023
49078b8
Merge branch 'master' into LP-169-breaks-labels-dict
OLarionova-HORIS Nov 27, 2023
642de35
Update doc: parameter 'breaks'.
OLarionova-HORIS Nov 27, 2023
b730619
Update notebook.
OLarionova-HORIS Nov 27, 2023
a029ec9
Update future_changes.md.
OLarionova-HORIS Nov 27, 2023
7da9462
Merge branch 'master' into LP-169-breaks-labels-dict
OLarionova-HORIS Nov 29, 2023
3c09856
Keep original order in breaks.
OLarionova-HORIS Nov 29, 2023
0edc4a1
Change description for 'breaks' parameter.
OLarionova-HORIS Nov 30, 2023
804fd94
Change description for parameter 'labels'.
OLarionova-HORIS Nov 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests.
  • Loading branch information
OLarionova-HORIS committed Nov 23, 2023
commit d6e4b5a820d51d8fca578fb53fb8be14fd0b4e57
57 changes: 57 additions & 0 deletions python-package/test/plot/test_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,60 @@ def test_scale_x_discrete():
assert as_dict['aesthetic'] == 'x'
assert as_dict['name'] == 'N'
assert as_dict['discrete']


# Use dictionary in scale_xxx(labels)

def test_scale_labels_dict():
spec = gg.scale_x_discrete(labels=dict(a="A", b="B", c="C"))
as_dict = spec.as_dict()
assert as_dict['breaks'] == ['a', 'b', 'c']
assert as_dict['labels'] == ['A', 'B', 'C']


def test_scale_labels_dict_with_specified_breaks():
spec = gg.scale_x_discrete(labels=dict(a="A", b="B", c="C"), breaks=['a', 'd', 'c'])
as_dict = spec.as_dict()
# use the order as in original 'breaks' + correct 'breaks' (without label - to the end of the list)
assert as_dict['breaks'] == ['a', 'c', 'd']
assert as_dict['labels'] == ['A', 'C']


def test_scale_labels_dict_no_matches_with_specified_breaks():
spec = gg.scale_x_discrete(labels=dict(a="A", b="B", c="C"), breaks=['d', 'e'])
as_dict = spec.as_dict()
assert as_dict['breaks'] == ['d', 'e']
assert as_dict['labels'] == []


# Use dictionary in scale_manual(values)

def test_scale_manual_values_dict():
spec = gg.scale_fill_manual(values=dict(a="A", b="B", c="C"))
as_dict = spec.as_dict()
assert as_dict['breaks'] == ['a', 'b', 'c']
assert as_dict['values'] == ['A', 'B', 'C']


def test_scale_manual_values_dict_with_specified_breaks():
spec = gg.scale_fill_manual(values=dict(a="A", b="B", c="C"), breaks=['a', 'c'])
as_dict = spec.as_dict()
# order as in original 'breaks', missing breaks - to the end of the list
assert as_dict['breaks'] == ['a', 'c']
assert as_dict['values'] == ['A', 'C', 'B']


def test_scale_manual_values_dict_with_specified_breaks_and_limits():
spec = gg.scale_fill_manual(values=dict(a="A", b="B", c="C"), breaks=['a', 'c'], limits=['b', 'c'])
as_dict = spec.as_dict()
# priority to 'limits' as a base list to choose the order of values
assert as_dict['breaks'] == ['a', 'c']
assert as_dict['limits'] == ['b', 'c']
assert as_dict['values'] == ['B', 'C', 'A']


def test_scale_manual_values_dict_no_matches_with_specified_breaks():
spec = gg.scale_fill_manual(values=dict(a="A", b="B", c="C"), breaks=['d', 'e'])
as_dict = spec.as_dict()
assert as_dict['breaks'] == ['d', 'e']
assert 'values' not in as_dict