Repository: spyder-ide/spyder

Issue:
Error when importing CSV  file from  Variable tab 
## Description

### What steps will reproduce the problem?

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

Importing CSV file from Variable tab will thow an error

### Traceback
```python-traceback
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 576, in _set_step
    self.text_widget.get_comments())
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 478, in open_data
    skiprows, comments)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 411, in process_data
    comments)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 391, in _shape_text
    from numpy import nan
ImportError: cannot import name 'nan' from 'numpy' (unknown location)
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 576, in _set_step
    self.text_widget.get_comments())
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 478, in open_data
    skiprows, comments)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 411, in process_data
    comments)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 391, in _shape_text
    from numpy import nan
ImportError: cannot import name 'nan' from 'numpy' (unknown location)
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 576, in _set_step
    self.text_widget.get_comments())
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 478, in open_data
    skiprows, comments)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 411, in process_data
    comments)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 391, in _shape_text
    from numpy import nan
ImportError: cannot import name 'nan' from 'numpy' (unknown location)
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 576, in _set_step
    self.text_widget.get_comments())
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 478, in open_data
    skiprows, comments)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 411, in process_data
    comments)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\importwizard.py", line 391, in _shape_text
    from numpy import nan
ImportError: cannot import name 'nan' from 'numpy' (unknown location)
```

## Versions

* Spyder version: 4.0.1 
* Python version: 3.7.5
* 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.2.2 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.11.1 (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.7.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.2 (OK)
zmq >=17                     :  18.1.0 (OK)
qdarkstyle >=2.7             :  2.7 (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.3.1 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  None (NOK)
matplotlib >=2.0.0           :  None (NOK)
numpy >=1.7                  :  None (NOK)
pandas >=0.13.1              :  None (NOK)
scipy >=0.17.0               :  None (NOK)
sympy >=0.7.3                :  None (NOK)
```



Discussion:
@yekhtiari could you provide a trimmed down version of the csv file that is causing these issues?

---

@dalthviz I tried with 
```csv
h1,h2,h3
1,2,3
4,5,6
```

And I got a different error (still it seems it is broken)

```python-traceback
Traceback (most recent call last):
  File "/Users/goanpeca/Dropbox (Personal)/develop/quansight/spyder/spyder/plugins/variableexplorer/widgets/importwizard.py", line 635, in process
    self.clip_data = self._get_table_data()
  File "/Users/goanpeca/Dropbox (Personal)/develop/quansight/spyder/spyder/plugins/variableexplorer/widgets/importwizard.py", line 615, in _get_table_data
    return array(data)
NameError: name 'array' is not defined
```
It seems we need to account for Numpy not being installed in the Import wizard dialog.
>It seems we need to account for Numpy not being installed in the Import wizard dialog.

True, although in my case is installed.... so weird...

What should we do in this case @ccordoba12 ?

Message the user or create a minimal numpy like wrapper ?


Your error appears when importing `array` from `numpy`:

https://github.com/spyder-ide/spyder/blob/e4c5b1a678b1e90be7191fa5c6f77acfb7aba8ca/spyder/plugins/variableexplorer/widgets/importwizard.py#L62-L67

The problem is we're not creating a `FakeObject` to stand for `array` in case the import fails.
>The problem is we're not creating a FakeObject to stand for array in case the import fails.

Correct
@goanpeca 
Here you go:
[tree.zip](https://github.com/spyder-ide/spyder/files/4242510/tree.zip)
![image](https://user-images.githubusercontent.com/28416805/75121081-9f166a80-5645-11ea-9ee2-93728376854b.png)
As you can see in the picture ,Next button is enabled,but clicking on it will error  out.Also preview tab is disabled.

Resolving patch:
diff --git a/spyder/plugins/variableexplorer/widgets/importwizard.py b/spyder/plugins/variableexplorer/widgets/importwizard.py
--- a/spyder/plugins/variableexplorer/widgets/importwizard.py
+++ b/spyder/plugins/variableexplorer/widgets/importwizard.py
@@ -60,11 +60,14 @@ class FakeObject(object):
     """Fake class used in replacement of missing modules"""
     pass
 try:
-    from numpy import ndarray, array
+    from numpy import ndarray
 except:
-    class ndarray(FakeObject):  # analysis:ignore
-        """Fake ndarray"""
-        pass
+    ndarray = FakeObject()  # analysis:ignore
+
+try:
+    from numpy import array
+except:
+    array = FakeObject()  # analysis:ignore
 
 #----date and datetime objects support
 import datetime
@@ -441,8 +444,11 @@ def __init__(self, parent):
         type_layout.addWidget(type_label)
 
         self.array_btn = array_btn = QRadioButton(_("array"))
-        array_btn.setEnabled(ndarray is not FakeObject)
-        array_btn.setChecked(ndarray is not FakeObject)
+        available_array = (
+            not isinstance(ndarray, FakeObject) and
+            not isinstance(array, FakeObject))
+        array_btn.setEnabled(available_array)
+        array_btn.setChecked(available_array)
         type_layout.addWidget(array_btn)
 
         list_btn = QRadioButton(_("list"))


Test patch: