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

Rejecting parameter 'positions' for boxplot(), refs #3566 #3576

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions seaborn/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,10 @@ def boxplot(
fliersize=None, hue_norm=None, native_scale=False, log_scale=None, formatter=None,
legend="auto", ax=None, **kwargs
):

if "positions" in kwargs:
msg = "boxplot() does not support parameter 'positions'. Consider to use native_scale=True and specify positions via parameter 'x'."
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
msg = "boxplot() does not support parameter 'positions'. Consider to use native_scale=True and specify positions via parameter 'x'."
msg = "boxplot does not support parameter `positions`. Consider using `native_scale=True`.

Nit: For a horizontal boxplot you'd specify the positions with y so let's make the suggestion less specific. Note that I've also tweaked the formatting.

raise ValueError(msg)
Copy link
Owner

Choose a reason for hiding this comment

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

Small thing but TypeError is probably a better error class here, that is what you get if you passed an undefined parameter. Alternatively, RuntimeError since positions is technically valid but produces incorrect behavior.


p = _CategoricalPlotter(
data=data,
Expand Down
20 changes: 19 additions & 1 deletion tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,25 @@
g = catplot(**kwargs, kind="box")

assert_plots_equal(ax, g.ax)



@pytest.mark.parametrize("positions", [None, [1, 2, 3, 4]])
def test_reject_boxpositions(self, positions):

kwargs = {
"x":[1, 2, 3, 4],
"y":[1, 1, 2, 2]
}

try:
boxplot(**kwargs, positions=positions)
err = None

Check warning on line 1183 in tests/test_categorical.py

View check run for this annotation

Codecov / codecov/patch

tests/test_categorical.py#L1183

Added line #L1183 was not covered by tests
except ValueError as e:
err = e

assert(err is not None)
Copy link
Owner

Choose a reason for hiding this comment

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

It would be slightly more idiomatic I think to use pytest.raises here, ideally with the match parameter to make sure we're getting the error we expect.




class TestBoxenPlot(SharedAxesLevelTests, SharedPatchArtistTests):

Expand Down
Loading