Repository: spyder-ide/spyder

Issue:
Variable explorer shows DatetimeIndex with numpy datetime64 format instead of timestamp
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->


## Problem Description

Pandas datetime index appears  in spyder 4 variable explorer with the very unfriendly numpy datetime64 format instead of timestamp.


### What steps reproduce the problem?

`import numpy as np`
`import pandas as pd`


`ds=pd.Series(np.arange(10),index=pd.date_range('2019-01-01',periods=10))`

### What is the expected output? What do you see instead?

Expected output (spyder 3.3.6):

![variable_explorer_spyder3](https://user-images.githubusercontent.com/36016034/71080412-606bbc00-218d-11ea-90ca-7ecf3af48f3c.PNG)

Spyder 4.0.0 output:

![variable_explorer_spyder4](https://user-images.githubusercontent.com/36016034/71080520-99a42c00-218d-11ea-8a93-986a2f569aed.PNG)



## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4.0.0
* Python version: 3.7.4
* Qt version: 5.9.7
* PyQt version:  5.9.2
* Operating System name/version: windows 10 x64

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
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.4 (OK)
cython >=0.21                :  0.29.14 (OK)
IPython >=4.0                :  7.10.1 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
pandas >=0.13.1              :  0.25.3 (OK)
numpy >=1.7                  :  1.17.4 (OK)
scipy >=0.17.0               :  1.3.2 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.2 (OK)
rtree >=0.8.3                :  0.8.3 (OK)

```



Discussion:
@dalthviz, please take a look at this one.

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
@@ -123,8 +123,6 @@ def __init__(self, dataFrame, format=DEFAULT_FORMAT, parent=None):
         QAbstractTableModel.__init__(self)
         self.dialog = parent
         self.df = dataFrame
-        self.df_index = dataFrame.index.tolist()
-        self.df_header = dataFrame.columns.tolist()
         self._format = format
         self.complex_intran = None
         self.display_error_idxs = []
@@ -199,7 +197,7 @@ def header(self, axis, x, level=0):
         given level.
         """
         ax = self._axis(axis)
-        return ax.values[x] if not hasattr(ax, 'levels') \
+        return ax.tolist()[x] if not hasattr(ax, 'levels') \
             else ax.values[x][level]
 
     def name(self, axis, level):
@@ -306,10 +304,6 @@ def get_value(self, row, column):
             value = self.df.iloc[row, column]
         return value
 
-    def update_df_index(self):
-        """"Update the DataFrame index"""
-        self.df_index = self.df.index.tolist()
-
     def data(self, index, role=Qt.DisplayRole):
         """Cell content"""
         if not index.isValid():
@@ -377,11 +371,9 @@ def sort(self, column, order=Qt.AscendingOrder):
                     # See spyder-ide/spyder#5361.
                     QMessageBox.critical(self.dialog, "Error",
                                          "SystemError: %s" % to_text_string(e))
-                self.update_df_index()
             else:
                 # To sort by index
                 self.df.sort_index(inplace=True, ascending=ascending)
-                self.update_df_index()
         except TypeError as e:
             QMessageBox.critical(self.dialog, "Error",
                                  "TypeError error: %s" % str(e))


Test patch:
diff --git a/spyder/plugins/variableexplorer/widgets/tests/test_dataframeeditor.py b/spyder/plugins/variableexplorer/widgets/tests/test_dataframeeditor.py
--- a/spyder/plugins/variableexplorer/widgets/tests/test_dataframeeditor.py
+++ b/spyder/plugins/variableexplorer/widgets/tests/test_dataframeeditor.py
@@ -23,7 +23,7 @@
 
 # Third party imports
 from pandas import (DataFrame, date_range, read_csv, concat, Index, RangeIndex,
-                    MultiIndex, CategoricalIndex)
+                    MultiIndex, CategoricalIndex, Series)
 from qtpy.QtGui import QColor
 from qtpy.QtCore import Qt, QTimer
 import numpy
@@ -80,10 +80,20 @@ def generate_pandas_indexes():
         }
 
 
-
 # =============================================================================
 # Tests
 # =============================================================================
+def test_dataframe_datetimeindex(qtbot):
+    """Regression test for spyder-ide/spyder#11129 ."""
+    ds = Series(
+        numpy.arange(10),
+        index=date_range('2019-01-01', periods=10))
+    editor = DataFrameEditor(None)
+    editor.setup_and_check(ds)
+    index = editor.table_index.model()
+    assert data_index(index, 0, 0) == '2019-01-01 00:00:00'
+    assert data_index(index, 9, 0) == '2019-01-10 00:00:00'
+
 
 def test_dataframe_simpleindex(qtbot):
     """Test to validate proper creation and handling of a simpleindex."""