File tree 4 files changed +39
-3
lines changed
4 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
title : Changelog
3
3
---
4
+ ## v0.13.6
5
+ (not-yet-released)
6
+
7
+ ### Enhancements
8
+
9
+ - Stopped spurious warnings of the form ``PlotnineWarning: Failed to apply
10
+ ` after_scale ` modifications to the legend.`` when the ` after_scale `
11
+ mapping is for another aesthetic.
4
12
5
13
## v0.13.5
6
14
(2024-04-26)
Original file line number Diff line number Diff line change @@ -160,16 +160,28 @@ def create_geoms(self):
160
160
continue
161
161
162
162
matched = self .legend_aesthetics (l )
163
+ matched_set = set (matched )
163
164
164
165
# This layer does not contribute to the legend
165
- if not set ( matched ) - exclude :
166
+ if not matched_set - exclude :
166
167
continue
167
168
168
169
data = self .key [matched ].copy ()
169
170
170
171
# Modify aesthetics
172
+
173
+ # When doing after_scale evaluations, we only consider those
174
+ # for the aesthetics of this legend. The reduces the spurious
175
+ # warnings where an evaluation of another aesthetic failed yet
176
+ # it is not needed.
177
+ aes_modifiers = {
178
+ ae : expr
179
+ for ae , expr in l .mapping ._scaled .items ()
180
+ if ae in matched_set
181
+ }
182
+
171
183
try :
172
- data = l .use_defaults (data )
184
+ data = l .use_defaults (data , aes_modifiers = aes_modifiers )
173
185
except PlotnineError :
174
186
warn (
175
187
"Failed to apply `after_scale` modifications "
Original file line number Diff line number Diff line change @@ -386,7 +386,7 @@ def use_defaults(
386
386
data = self .data
387
387
388
388
if aes_modifiers is None :
389
- aes_modifiers = self . mapping . _scaled
389
+ aes_modifiers = {}
390
390
391
391
return self .geom .use_defaults (data , aes_modifiers )
392
392
Original file line number Diff line number Diff line change
1
+ import warnings
2
+
3
+ from plotnine import (
4
+ aes ,
5
+ geom_point ,
6
+ ggplot ,
7
+ )
8
+ from plotnine .data import mtcars
9
+
10
+
11
+ def test_no_after_scale_warning ():
12
+ p = ggplot (mtcars , aes ("wt" , "mpg" )) + geom_point ()
13
+
14
+ with warnings .catch_warnings ():
15
+ warnings .simplefilter ("error" )
16
+ p .draw_test () # type: ignore
You can’t perform that action at this time.
0 commit comments