Repository: spyder-ide/spyder

Issue:
Unable to delete multiple variables in Variable Explorer
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Run the 2 lines of code.
# initialize list of lists 
import pandas as pd

data = [['tom', 10], ['nick', 15], ['juli', 14]] 
  
# Create the pandas DataFrame 
df = pd.DataFrame(data, columns = ['Name', 'Age']) 

Then using Variable explorer try to "remove" both lines.

One line removes and the other does not.

Then try to remove the one that is still displaying.

It is pretty consistent.

### Traceback
```python-traceback
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 790, in contextMenuEvent
    self.refresh_menu()
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 707, in refresh_menu
    self.refresh_plot_entries(index)
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 712, in refresh_plot_entries
    is_list = self.is_list(key)
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1464, in is_list
    return self.var_properties[name]['is_list']
KeyError: 'df'
Traceback (most recent call last):
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 790, in contextMenuEvent
    self.refresh_menu()
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 707, in refresh_menu
    self.refresh_plot_entries(index)
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 712, in refresh_plot_entries
    is_list = self.is_list(key)
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1464, in is_list
    return self.var_properties[name]['is_list']
KeyError: 'df'
Traceback (most recent call last):
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 790, in contextMenuEvent
    self.refresh_menu()
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 707, in refresh_menu
    self.refresh_plot_entries(index)
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 712, in refresh_plot_entries
    is_list = self.is_list(key)
  File "C:\Users\jmonroe1\AppData\Roaming\Python\Python37\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1464, in is_list
    return self.var_properties[name]['is_list']
KeyError: 'df'
```

## Versions

* Spyder version: 4.0.1 
* Python version: 3.7.4
* Qt version: 5.12.6
* PyQt5 version: 5.12.3
* 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.2.2 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.8.0 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
nbconvert >=4.0              :  5.6.0 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
pexpect >=4.4.0              :  4.8.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.6.3 (OK)
pygments >=2.0               :  2.4.2 (OK)
pylint >=0.25                :  2.4.2 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.7 (OK)
zmq >=17                     :  18.1.0 (OK)
qdarkstyle >=2.7             :  2.8 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
sphinx >=0.6.6               :  2.2.0 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  0.29.13 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
numpy >=1.7                  :  1.16.5 (OK)
pandas >=0.13.1              :  0.25.1 (OK)
scipy >=0.17.0               :  1.3.1 (OK)
sympy >=0.7.3                :  1.4 (OK)
```

KeyError when removing variables in the Variable Explorer
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

The variable explorer is filled with variables that appear from nothing like pi, e, or NoneType

### Traceback
```python-traceback
Exception in comms call remove_value:
  File "C:\Users\gianf\anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 342, in _handle_remote_call
    buffer['call_kwargs'])
  File "C:\Users\gianf\anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
    *call_args, **call_kwargs)
  File "C:\Users\gianf\anaconda\lib\site-packages\spyder_kernels\console\kernel.py", line 234, in remove_value
    ns.pop(name)
KeyError: 'ScalarType'
```

## Versions

* Spyder version: 4.0.0 
* Python version: 3.7.1
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```
cloudpickle >=0.5.0          :  1.2.2 (OK)
pygments >=2.0               :  2.5.2 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
sphinx >=0.6.6               :  2.2.2 (OK)
pylint >=0.25                :  2.4.4 (OK)
psutil >=0.3                 :  5.6.7 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.3 (OK)
cython >=0.21                :  0.29.2 (OK)
IPython >=4.0                :  7.10.1 (OK)
matplotlib >=2.0.0           :  3.0.2 (OK)
pandas >=0.13.1              :  0.25.3 (OK)
numpy >=1.7                  :  1.17.4 (OK)
scipy >=0.17.0               :  1.1.0 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.2 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
```



Discussion:
I finally could reproduce this, but for the second time: please **do not** open a new issue about this in case the error appears for you in the future. It's just a waste of time for me because I have to look for your older issue and close it.

I still don't know how to fix it though.
What variable did you try to remove when this error appeared?
After I remove some numpy arrays. This is the list of variables that appear:

Il giorno mar 10 dic 2019 alle ore 17:40 Carlos Cordoba <
notifications@github.com> ha scritto:

> What variable did you try to remove when this error appeared?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/spyder-ide/spyder/issues/11001?email_source=notifications&email_token=ANIMVHYNRXUDUOHBOL637N3QX7BBJA5CNFSM4JZBFKG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGP433Q#issuecomment-564121070>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ANIMVH5S5EXCJGAZMRACSGLQX7BBJANCNFSM4JZBFKGQ>
> .
>

And when I try to delete them with remove varibales it doesn't do it. I
have to remove them manually.

Il giorno mar 10 dic 2019 alle ore 17:54 Dario Liscai <liscai.d99@gmail.com>
ha scritto:

> After I remove some numpy arrays. This is the list of variables that
> appear:
>
> Il giorno mar 10 dic 2019 alle ore 17:40 Carlos Cordoba <
> notifications@github.com> ha scritto:
>
>> What variable did you try to remove when this error appeared?
>>
>> —
>> You are receiving this because you authored the thread.
>> Reply to this email directly, view it on GitHub
>> <https://github.com/spyder-ide/spyder/issues/11001?email_source=notifications&email_token=ANIMVHYNRXUDUOHBOL637N3QX7BBJA5CNFSM4JZBFKG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGP433Q#issuecomment-564121070>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/ANIMVH5S5EXCJGAZMRACSGLQX7BBJANCNFSM4JZBFKGQ>
>> .
>>
>

Do you have a `from numpy import *` in your code? This line would import the variables you are describing.

Resolving patch:
diff --git a/spyder/plugins/variableexplorer/widgets/collectionseditor.py b/spyder/plugins/variableexplorer/widgets/collectionseditor.py
--- a/spyder/plugins/variableexplorer/widgets/collectionseditor.py
+++ b/spyder/plugins/variableexplorer/widgets/collectionseditor.py
@@ -742,6 +742,7 @@ def set_data(self, data):
         """Set table data"""
         if data is not None:
             self.source_model.set_data(data, self.dictfilter)
+            self.source_model.reset()
             self.sortByColumn(0, Qt.AscendingOrder)
 
     def mousePressEvent(self, event):


Test patch: