sanitize norm extrema to be floats - #10721
Conversation
If you set
The changes I made to |
|
If I run the following on master and import numpy as np
import matplotlib
import matplotlib.colors as mcolors
class MyArray(np.ndarray):
def __isub__(self, other):
raise RuntimeError
def __add__(self, other):
raise RuntimeError
data = np.arange(-10, 10, 1, dtype=float)
mydata = data.view(MyArray)
for norm in [mcolors.Normalize(vmin=mydata.min(), vmax=mydata.max()),
mcolors.SymLogNorm(3, vmin=mydata.min(), vmax=mydata.max())]:
print(np.all(norm(mydata) == norm(data))) |
|
@jklymak thanks! It looks like you actually have to use the |
|
Ha, given that I just got a slap on the wrist for my test writing, please no apologies! We did change some image normalization stuff recently, hence I wanted to make sure that we didn't miss something. i.e. #10613 worse, that one didn't get in for the RC, but was in response to a bug report after the RC, so its possible we (ahem, I) fixed one thing and broke another. |
|
@jklymak updated the test. Here's a script that I verified should fail on 2.2.0: |
Backport PR #10721 on branch v2.2.x

PR Summary
Fix regression from 2.1.2 by ensuring norm extrema are always floats.
PR Checklist
PR Description
We had a report from a yt user complaining about saving plots to disk raising errors in some cases:
https://mail.python.org/mm3/archives/list/yt-users@python.org/thread/24OJRJVPK47RMG7XLF7J7YP4JQH24MG7/
I was able to reproduce this issue on matplotlib 2.2.0 but not on matplotlib 2.1.2 and earlier, so this is a regression.
I believe this behavior was unintentionally introduced by @anntzer in #6700 to avoid rounding issues with
float128on linux. As a side-effect that PR changed how matplotlib deals with data with units attached.I've added a
_sanitize_extremahelper so that we can usenp.asscalarto avoid downcastingfloat128data while still converting data to a numpy scalar under the hood. I've also expanded the existing test intest_colors.pythat handles ndarray subclass to also check this case as well.It would be great if this could be backported to 2.2.