Skip to content

Commit 315abf1

Browse files
committed
Warn when aesthetics are dropped during stat processing
1 parent 7ea0d9e commit 315abf1

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

plotnine/stats/stat.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import typing
44
from copy import deepcopy
5+
from warnings import warn
56

67
import pandas as pd
78

@@ -33,6 +34,13 @@
3334
"na_rm": False,
3435
}
3536

37+
DROPPED_TPL = """
38+
The following aesthetics were dropped during processing: {dropped}.
39+
plotnine could not infer the correct grouping.
40+
Did you forget to specify a `group` aesthetic or to convert a numerical \
41+
variable into a categorial?
42+
"""
43+
3644

3745
class stat(ABC, metaclass=Register):
3846
"""Base class of all stats"""
@@ -307,6 +315,9 @@ def compute_panel(self, data: pd.DataFrame, scales: pos_scales):
307315
stats.append(group_result)
308316

309317
stats = pd.concat(stats, axis=0, ignore_index=True)
318+
dropped = data.columns.difference(stats.columns).to_list()
319+
if dropped:
320+
warn(DROPPED_TPL.format(dropped=dropped))
310321
# Note: If the data coming in has columns with non-unique
311322
# values with-in group(s), this implementation loses the
312323
# columns. Individual stats may want to do some preparation

0 commit comments

Comments
 (0)