Skip to content

Commit b65c501

Browse files
committed
Add DROPPED_AES to suppress expected dropped-aesthetic warnings
Declares which aesthetics each stat is expected to discard during processing so the warning introduced in 315abf1 only fires for unexpected drops. closes #1049
1 parent f844850 commit b65c501

13 files changed

Lines changed: 24 additions & 1 deletion

plotnine/stats/stat.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ class stat(ABC, metaclass=Register):
5757
DEFAULT_PARAMS: dict[str, Any] = {}
5858
"""Required parameters for the stat"""
5959

60+
DROPPED_AES: list[str] = []
61+
"""
62+
Aesthetics that may be dropped during processing.
63+
64+
These are typically common aesthetics that a particular stat does not use.
65+
If a value is mapped to any of these aesthetics, the stat may discard them
66+
silently (without issuing a warning).
67+
"""
68+
6069
CREATES: set[str] = set()
6170
"""
6271
Stats may modify existing columns or create extra
@@ -315,7 +324,9 @@ def compute_panel(self, data: pd.DataFrame, scales: pos_scales):
315324
stats.append(group_result)
316325

317326
stats = pd.concat(stats, axis=0, ignore_index=True)
318-
dropped = data.columns.difference(stats.columns).to_list()
327+
dropped = data.columns.difference(
328+
stats.columns.union(self.DROPPED_AES)
329+
).to_list()
319330
if dropped:
320331
warn(DROPPED_TPL.format(dropped=dropped))
321332
# Note: If the data coming in has columns with non-unique

plotnine/stats/stat_bin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class stat_bin(stat):
8787
}
8888
DEFAULT_AES = {"y": after_stat("count"), "weight": None}
8989
CREATES = {"width", "count", "density", "ncount", "ndensity", "ngroup"}
90+
DROPPED_AES = ["weight"]
9091

9192
def setup_params(self, data):
9293
params = self.params

plotnine/stats/stat_bin_2d.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class stat_bin_2d(stat):
6666
}
6767
DEFAULT_AES = {"fill": after_stat("count"), "weight": None}
6868
CREATES = {"xmin", "xmax", "ymin", "ymax", "count", "density"}
69+
DROPPED_AES = ["weight"]
6970

7071
def setup_params(self, data):
7172
params = self.params

plotnine/stats/stat_bindot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class stat_bindot(stat):
103103
}
104104
DEFAULT_AES = {"y": after_stat("count")}
105105
CREATES = {"width", "count", "density", "ncount", "ndensity"}
106+
DROPPED_AES = ["weight", "bin", "bincenter"]
106107

107108
def setup_params(self, data):
108109
params = self.params

plotnine/stats/stat_boxplot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class stat_boxplot(stat):
8080
"relvarwidth",
8181
"n",
8282
}
83+
DROPPED_AES: list[str] = ["x", "y", "weight"]
8384

8485
def setup_data(self, data):
8586
if "x" not in data:

plotnine/stats/stat_count.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class stat_count(stat):
4747
}
4848
DEFAULT_AES = {"y": after_stat("count")}
4949
CREATES = {"count", "prop"}
50+
DROPPED_AES = ["weight"]
5051

5152
def setup_params(self, data):
5253
if self.params["width"] is None:

plotnine/stats/stat_density.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class stat_density(stat):
123123
}
124124
DEFAULT_AES = {"y": after_stat("density")}
125125
CREATES = {"density", "count", "scaled", "n"}
126+
DROPPED_AES = ["weight"]
126127

127128
def setup_params(self, data):
128129
params = self.params

plotnine/stats/stat_ecdf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class stat_ecdf(stat):
4343
DEFAULT_PARAMS = {"geom": "step", "n": None, "pad": True}
4444
DEFAULT_AES = {"y": after_stat("ecdf")}
4545
CREATES = {"ecdf"}
46+
DROPPED_AES = ["weight"]
4647

4748
def compute_group(self, data, scales):
4849
from statsmodels.distributions.empirical_distribution import ECDF

plotnine/stats/stat_ellipse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class stat_ellipse(stat):
5050
"level": 0.95,
5151
"segments": 51,
5252
}
53+
DROPPED_AES = ["weight"]
5354

5455
def compute_group(self, data, scales):
5556
import scipy.stats as stats

plotnine/stats/stat_qq_line.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class stat_qq_line(stat):
6262
"fullrange": False,
6363
}
6464
CREATES = {"x", "y"}
65+
DROPPED_AES = ["sample"]
6566

6667
def setup_params(self, data):
6768
if len(self.params["line_p"]) != 2:

0 commit comments

Comments
 (0)