C:\WinPython\basedir35\buildQt5\winpython-64bit-3.5.x.3\python-3.5.2.amd64\lib\site-packages\matplotlib\colors.py:486: RuntimeWarning: invalid value encountered in less
cbook._putmask(xa, xa < 0.0, -1)
Do you have any idea what values are going in when the warning is raised? If I am reading in right, it looks like the warning is coming out of the xa < 0 .
Colormap.__call__() is assuming it's input contains no unmasked invalid values. Normally this doesn't cause a problem because we use masked_invalid in enough places that invalid values don't find their way into the call argument. Evidently we need to call masked_invalid in even more places, such as this.
I'm using Numpy-1.11.1 and pandas-0.19.0rc1 of of cgohlke.
This test was the what's new in pandas 0.18 presentation of Jeff Reback ... can't find the youtube. Just to say there was no issue with that with previous Pandas/Matplotlib
This is some very strange interactions between the libraries. I am 90% sure that the warning is actually coming out of numpy, but very confused why changing the pandas version affects it.
So I could trim the reproducing example down to df.style.background_gradient().
What this background_gradient method more or less does under the hood is the following (and this may have changed):
And it is the last line that triggers the warning. So in any case anything to do with pandas itself anymore (but maybe with a wrong way we call things in matplotlib)
Digged a little bit further, in the call method of Colormaps, basically the following happens:
In [16]: from matplotlib import cbook
In [17]: X = np.array([np.nan, 1, 0.5])
In [18]: xa = np.array([X])
In [19]: cbook._putmask(xa, xa < 0, -1)
/home/joris/miniconda3/envs/dev/bin/ipython:1: RuntimeWarning: invalid value encountered in less
#!/home/joris/miniconda3/envs/dev/bin/python
In [20]: xa < 1
/home/joris/miniconda3/envs/dev/bin/ipython:1: RuntimeWarning: invalid value encountered in less
#!/home/joris/miniconda3/envs/dev/bin/python
Out[20]: array([[False, False, True]], dtype=bool)
So it is indeed just coming from numpy by this comparison with NaNs
changed the title [-]error using IpythonWidgets + Seaborn on Matplotlib-2.0.0b4[/-][+]Document input requirements on `Colormap.__call__`[/+]on Sep 20, 2016
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
tacaswell commented on Sep 18, 2016
Do you have any idea what values are going in when the warning is raised? If I am reading in right, it looks like the warning is coming out of the xa < 0 .
stonebig commented on Sep 18, 2016
the seed paramater generates always the same subset:

And there IS no error if I tag the nan affectation:
stonebig commented on Sep 18, 2016
maybe it's a practice that is no more allowed ? maybe it's a rather a pandas bug ?
tacaswell commented on Sep 18, 2016
I am pretty sure that this is coming out of numpy. What version of numpy/pandas do you have installed?
Can you reproduce this without pandas, jupyter, or seaborn?
efiring commented on Sep 19, 2016
Colormap.__call__() is assuming it's input contains no unmasked invalid values. Normally this doesn't cause a problem because we use masked_invalid in enough places that invalid values don't find their way into the call argument. Evidently we need to call masked_invalid in even more places, such as this.
stonebig commented on Sep 19, 2016
I'm using Numpy-1.11.1 and pandas-0.19.0rc1 of of cgohlke.
This test was the what's new in pandas 0.18 presentation of Jeff Reback ... can't find the youtube. Just to say there was no issue with that with previous Pandas/Matplotlib
stonebig commented on Sep 20, 2016
ok:
(numpy being untouched)
==> wouldn't it be rather a Pandas issue ?
tacaswell commented on Sep 20, 2016
This is some very strange interactions between the libraries. I am 90% sure that the warning is actually coming out of numpy, but very confused why changing the pandas version affects it.
jorisvandenbossche commented on Sep 20, 2016
So I could trim the reproducing example down to df.style.background_gradient().
What this background_gradient method more or less does under the hood is the following (and this may have changed):
And it is the last line that triggers the warning. So in any case anything to do with pandas itself anymore (but maybe with a wrong way we call things in matplotlib)
jorisvandenbossche commented on Sep 20, 2016
So in the above example, normed is a masked array but where the data includes a NaN. It is this were the colormap gives a warning:
In [3]: plt.cm.get_cmap('viridis')(np.array([np.nan, 1, 0.5])) /home/joris/miniconda3/envs/dev/lib/python3.5/site-packages/matplotlib/colors.py:581: RuntimeWarning: invalid value encountered in less cbook._putmask(xa, xa < 0.0, -1) Out[3]: array([[ 0.267004, 0.004874, 0.329415, 1. ], [ 0.993248, 0.906157, 0.143936, 1. ], [ 0.127568, 0.566949, 0.550556, 1. ]]) In [5]: plt.cm.get_cmap('viridis')(np.array([np.nan])) Out[5]: array([[ 0.267004, 0.004874, 0.329415, 1. ]])A strange thing is that it does not give the warning when it is a array with a single nan value.
Is cmap supposed to be able to deal with NaNs? Or should we in pandas filter them out first?
jorisvandenbossche commented on Sep 20, 2016
Digged a little bit further, in the call method of Colormaps, basically the following happens:
So it is indeed just coming from numpy by this comparison with NaNs
tacaswell commented on Sep 20, 2016
I am unclear what changed that there is now a warning where there was not before.
jorisvandenbossche commented on Sep 20, 2016
Since it is coming straight from numpy (the last line in my example, pure numpy), I am also not sure.
jorisvandenbossche commented on Sep 20, 2016
Ah, pandas 0.19.0rc1 no longer suppresses certain numpy warnings as it did before: pandas-dev/pandas#13145. That is probably the reason.
1 remaining item
tacaswell commented on Sep 20, 2016
It should be masked on the pandas side, we should clarify the docs on __call__ if needed.
tacaswell commented on Sep 20, 2016
@jorisvandenbossche Thanks for doing the leg work to track this down, it is greatly appreciated.
jorisvandenbossche commented on Sep 20, 2016
No problem! OK, then I keep the issue open on the pandas side and repurposed it to deal with NaN values before passing them to cmap
QuLogic commented on Jul 8, 2021
cbook._putmask no longer exists, and Colormap.__call__ masks NaNs:
matplotlib/lib/matplotlib/colors.py
Line 606 in 4d1cd5e
The single line reproducer plt.cm.get_cmap('viridis')(np.array([np.nan, 1, 0.5])) doesn't warn either, so is there really anything left to do here?
github-actions commented on Mar 29, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!