Repository: spyder-ide/spyder

Issue:
ZeroDivisionError when viewing dataframes
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

### Traceback
```python-traceback
  File "C:\Users\mowang\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\dataframeeditor.py", line 341, in data
    return to_qvariant(self.get_bgcolor(index))
  File "C:\Users\mowang\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\dataframeeditor.py", line 288, in get_bgcolor
    (vmax - color_func(value)) / (vmax - vmin))
ZeroDivisionError: float division by zero
```

## Versions

* Spyder version: 4.0.1 
* Python version: 3.7.6
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```
atomicwrites >=1.2.0         :  1.3.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.12.0 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
numpydoc >=0.6.0             :  0.9.2 (OK)
pexpect >=4.4.0              :  4.8.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.6.7 (OK)
pygments >=2.0               :  2.5.2 (OK)
pylint >=0.25                :  2.4.4 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.7 (OK)
zmq >=17                     :  18.1.1 (OK)
qdarkstyle >=2.7             :  2.8 (OK)
qtawesome >=0.5.7            :  0.6.1 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.9.3 (OK)
sphinx >=0.6.6               :  2.4.0 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  0.29.15 (OK)
matplotlib >=2.0.0           :  3.1.3 (OK)
numpy >=1.7                  :  1.18.1 (OK)
pandas >=0.13.1              :  0.25.1 (OK)
scipy >=0.17.0               :  1.4.1 (OK)
sympy >=0.7.3                :  1.5.1 (OK)
```



Discussion:
@manfredwang093 could you provide more information?

Your title and steps to reproduce are all `?`. Without more information we cannot provide further asssitance.
Thanks for your email, Gonzalo. I am not sure what' s the error. My spyder
works fine, didn't crash or anything. This error report window pop out when
I opened and tried to view a pandas dataframe, which contains only float
and integer columns. It's also not very large. Shape is 1000x70.

mw.

On Thu, 12 Mar 2020 at 19:29, Gonzalo Peña-Castellanos <
notifications@github.com> wrote:

> @manfredwang093 <https://github.com/manfredwang093> could you provide
> more information?
>
> Your title and steps to reproduce are all ?. Without more information we
> cannot provide further asssitance.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/spyder-ide/spyder/issues/11790#issuecomment-598476522>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AFIZUILBP2JSMRTNPHZLAFTRHFV63ANCNFSM4LGXGMBA>
> .
>

@manfredwang093 if you could provide an example (that we can reproduce on our side) it could help to narrow the problem so please share a minimal code example we can try that consistently generates the error dialog pop up.
But the error was not associate with any code..... The error window showed
up when I double clicked open a dataframe in 'Variable Explorer'. After I
maximized the opened data frame window, the error window popped up.



On Thu, 12 Mar 2020 at 23:20, Gonzalo Peña-Castellanos <
notifications@github.com> wrote:

> @manfredwang093 <https://github.com/manfredwang093> if you could provide
> an example (that we can reproduce on our side) it could help to narrow the
> problem so please share a minimal code example we can try that consistently
> generates the error dialog pop up.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/spyder-ide/spyder/issues/11790#issuecomment-598529195>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AFIZUIL7PKSY7VHNFRHSVNTRHGQ57ANCNFSM4LGXGMBA>
> .
>

Yeah, what we really we need is the data you used to generate your dataframe.
Unfortunately....it's not public data....

On Thu, 12 Mar 2020 at 23:39, Carlos Cordoba <notifications@github.com>
wrote:

> Yeah, what we really we need is the data you used to generate your
> dataframe.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/spyder-ide/spyder/issues/11790#issuecomment-598533145>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AFIZUIPLZVX3TUQ66JESJM3RHGTIHANCNFSM4LGXGMBA>
> .
>

Is there a column on them where the max and min values are the same?
Yes, there are columns with the same value. I just tried again, actually
the error window popped up when I was trying to scroll to the right to view
more columns, after maximized the data frame window.

Below is some information about the data frame causing issue.

   - Table dimension is 1375x71.
   - There are only integer and float values in data frame, but there are
   very long float values, like: -1.39E+36
   - There are many zero variance columns

Hope these information helps.





On Thu, 12 Mar 2020 at 23:49, Carlos Cordoba <notifications@github.com>
wrote:

> Is there a column on them where the max and min values are the same?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/spyder-ide/spyder/issues/11790#issuecomment-598535007>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AFIZUIKIWQ4TIGGFY5PXDWLRHGUNRANCNFSM4LGXGMBA>
> .
>

@dalthviz, please try to reproduce and fix this one.
Hello, I just managed to reproduce the error when opening the Pandas variable explorer of the attached file.
[error.txt](https://github.com/spyder-ide/spyder/files/4331915/error.txt)



Resolving patch:
diff --git a/spyder/plugins/variableexplorer/widgets/dataframeeditor.py b/spyder/plugins/variableexplorer/widgets/dataframeeditor.py
--- a/spyder/plugins/variableexplorer/widgets/dataframeeditor.py
+++ b/spyder/plugins/variableexplorer/widgets/dataframeeditor.py
@@ -283,8 +283,12 @@ def get_bgcolor(self, index):
             else:
                 color_func = float
             vmax, vmin = self.return_max(self.max_min_col, column)
+            if vmax - vmin == 0:
+                vmax_vmin_diff = 1.0
+            else:
+                vmax_vmin_diff = vmax - vmin
             hue = (BACKGROUND_NUMBER_MINHUE + BACKGROUND_NUMBER_HUERANGE *
-                   (vmax - color_func(value)) / (vmax - vmin))
+                   (vmax - color_func(value)) / (vmax_vmin_diff))
             hue = float(abs(hue))
             if hue > 1:
                 hue = 1


Test patch: