Skip to content
Merged
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
6 changes: 4 additions & 2 deletions plotnine/stats/stat_summary_bin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, cast
from warnings import warn

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -107,8 +108,9 @@ class stat_summary_bin(stat):
def setup_params(self, data):
keys = ("fun_data", "fun_y", "fun_ymin", "fun_ymax")
if not any(self.params[k] for k in keys):
PlotnineWarning(
"No summary function, supplied, defaulting to mean_se()"
warn(
"No summary function supplied, defaulting to mean_se()",
PlotnineWarning,
)
self.params["fun_data"] = "mean_se"

Expand Down
10 changes: 10 additions & 0 deletions tests/test_stat_summary_bin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import numpy as np
import pandas as pd
import pytest

from plotnine import aes, ggplot, stat_summary_bin
from plotnine.exceptions import PlotnineWarning

data = pd.DataFrame(
{
Expand Down Expand Up @@ -31,3 +33,11 @@ def test_continuous_x():
def test_setting_binwidth():
p = ggplot(data, aes("xc", "y")) + stat_summary_bin(binwidth=3, geom="bar")
assert p == "setting_binwidth"


def test_no_summary_function_warns():
# A missing summary function falls back to mean_se(), and the
# fallback must be announced.
p = ggplot(data, aes("xc", "y")) + stat_summary_bin(bins=5)
with pytest.warns(PlotnineWarning, match="defaulting to mean_se"):
p._build()
Loading