From a87e1de37077f3dd1031696b3526badd1ccc4897 Mon Sep 17 00:00:00 2001 From: sbreton Date: Thu, 30 Nov 2023 15:40:48 +0100 Subject: [PATCH 1/2] title_quantiles inherits quantiles values only if len(quantiles)==3, update accordingly documentation for show_title and title_quantiles --- src/corner/core.py | 7 +++++-- src/corner/corner.py | 10 ++++++---- tests/test_corner.py | 5 ++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/corner/core.py b/src/corner/core.py index 050a600..b529c8c 100644 --- a/src/corner/core.py +++ b/src/corner/core.py @@ -71,9 +71,12 @@ def corner_impl( if titles is None: titles = labels - # deal with title quantiles so they much quantiles unless desired otherwise + # If title_quantiles is not supplied, provide the + # value from quantiles if and only len (quantiles) + # is 3, otherwise fall back to default [0.16, 0.5, 0.84] + # value if title_quantiles is None: - if len(quantiles) > 0: + if len(quantiles) == 3: title_quantiles = quantiles else: # a default for when quantiles not supplied. diff --git a/src/corner/corner.py b/src/corner/corner.py index e4f54ad..2233624 100644 --- a/src/corner/corner.py +++ b/src/corner/corner.py @@ -140,13 +140,15 @@ def corner( uses labels as titles. show_titles : bool - Displays a title above each 1-D histogram showing the 0.5 quantile - with the upper and lower errors supplied by the quantiles argument. + Displays a title above each 1-D histogram showing the middle value, + lower and upper error as specified by the quantiles values provided + in `title_quantiles`. title_quantiles : iterable A list of 3 fractional quantiles to show as the the upper and lower - errors. If `None` (default), inherit the values from quantiles, unless - quantiles is `None`, in which case it defaults to [0.16,0.5,0.84] + errors. If `None` (default), and if `quantiles` has exactly three + element, inherit the values from `quantiles`. Otherwise, it defaults + to [0.16,0.5,0.84] title_fmt : string The format string for the quantiles given in titles. If you explicitly diff --git a/tests/test_corner.py b/tests/test_corner.py index 6130719..0ed1314 100644 --- a/tests/test_corner.py +++ b/tests/test_corner.py @@ -115,11 +115,14 @@ def test_title_quantiles_default(): ) def test_title_quantiles_raises(): with pytest.raises(ValueError): - _run_corner(quantiles=[0.05, 0.16, 0.5, 0.84, 0.95], show_titles=True) + _run_corner(title_quantiles=[0.05, 0.16, 0.5, 0.84, 0.95], show_titles=True) # This one shouldn't raise since show_titles isn't provided _run_corner(quantiles=[0.05, 0.16, 0.5, 0.84, 0.95]) +def test_len_quantiles (): + # This test should not raise an error, as title_quantile should default to [0.16, 0.5, 0.84] + _run_corner(quantiles=[0.05, 0.16, 0.5, 0.84, 0.95], show_titles=True) @image_comparison( baseline_images=["color"], remove_text=True, extensions=["png"] From 388b459a9faf48ae80796fe14dd6053758d3b899 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:50:14 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/corner/corner.py | 4 ++-- tests/test_corner.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/corner/corner.py b/src/corner/corner.py index 2233624..ed367de 100644 --- a/src/corner/corner.py +++ b/src/corner/corner.py @@ -141,13 +141,13 @@ def corner( show_titles : bool Displays a title above each 1-D histogram showing the middle value, - lower and upper error as specified by the quantiles values provided + lower and upper error as specified by the quantiles values provided in `title_quantiles`. title_quantiles : iterable A list of 3 fractional quantiles to show as the the upper and lower errors. If `None` (default), and if `quantiles` has exactly three - element, inherit the values from `quantiles`. Otherwise, it defaults + element, inherit the values from `quantiles`. Otherwise, it defaults to [0.16,0.5,0.84] title_fmt : string diff --git a/tests/test_corner.py b/tests/test_corner.py index 0ed1314..639ddc6 100644 --- a/tests/test_corner.py +++ b/tests/test_corner.py @@ -115,15 +115,19 @@ def test_title_quantiles_default(): ) def test_title_quantiles_raises(): with pytest.raises(ValueError): - _run_corner(title_quantiles=[0.05, 0.16, 0.5, 0.84, 0.95], show_titles=True) + _run_corner( + title_quantiles=[0.05, 0.16, 0.5, 0.84, 0.95], show_titles=True + ) # This one shouldn't raise since show_titles isn't provided _run_corner(quantiles=[0.05, 0.16, 0.5, 0.84, 0.95]) -def test_len_quantiles (): + +def test_len_quantiles(): # This test should not raise an error, as title_quantile should default to [0.16, 0.5, 0.84] _run_corner(quantiles=[0.05, 0.16, 0.5, 0.84, 0.95], show_titles=True) + @image_comparison( baseline_images=["color"], remove_text=True, extensions=["png"] )