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

Allow title_quantiles inheritance from quantiles only if len (quantiles)==3 #244

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions src/corner/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions src/corner/corner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion tests/test_corner.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,19 @@ 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"]
)
Expand Down