Repository: spyder-ide/spyder

Issue:
DataFrame viewer resizes the index column wrongly
### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] ~~Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)~~
I am seeing this with Spyder 3.3.0, which already is the latest release on PyPI.
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] ~~Reset preferences with ``spyder --reset`` / Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)~~
           I am using Spyder from freshly installed WinPython64-3.7.0.1
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
The `Resize` button in the DataFrame viewer fails to resize the index column correctly.


### What steps reproduce the problem?

1. Define `df = pd.DataFrame(data=[42], index=['long-index-value'])`
2. Open `df` in the DataFrame viewer.
3. Click `Resize`.

### What is the expected output? What do you see instead?
I see the following broken display:
![wrong-index-resize](https://user-images.githubusercontent.com/21648/43724765-19637a94-999b-11e8-91f6-7a4b0b7e1a99.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: 3.3.0
* Python version: 3.7.0 64bits
* Qt version: 5.9.3
* PyQt version: 5.9.2
* Operating System name/version: Windows 7

### Dependencies
<details>
<summary>Click to expand</summary>

```
IPython >=4.0     :  6.4.0 (OK)
cython >=0.21     :  0.28.3 (OK)
jedi >=0.9.0      :  0.12.1 (OK)
matplotlib >=2.0.0:  2.2.2 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
numpy >=1.7       :  1.14.5 (OK)
pandas >=0.13.1   :  0.23.3 (OK)
pycodestyle >=2.3 :  2.4.0 (OK)
pyflakes >=0.6.0  :  2.0.0 (OK)
pygments >=2.0    :  2.2.0 (OK)
pylint >=0.25     :  1.9.2 (OK)
qtconsole >=4.2.0 :  4.3.1 (OK)
rope >=0.9.4      :  0.10.7 (OK)
sphinx >=0.6.6    :  1.7.5 (OK)
sympy >=0.7.3     :  1.1.1 (OK)
```
</details>


Discussion:
I think we don't apply the resize operation to the Index column, but this could be fixed in our master branch.

@dalthviz, what's the behavior after your changes in master?
@ccordoba12 after the resize this is what you see:

![imagen](https://user-images.githubusercontent.com/16781833/43761567-14ee2cb6-99eb-11e8-9b4d-8c663ca46616.png)

However, before the resize, you see something like this:

![imagen](https://user-images.githubusercontent.com/16781833/43761720-7e59c49e-99eb-11e8-88e3-1f68d610d8af.png)

Ok, @dalthviz, please work to resize the Index column to its longest content or a maximum size.

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
@@ -878,7 +878,7 @@ def setup_and_check(self, data, title=''):
         self.dataTable.installEventFilter(self)
 
         avg_width = self.fontMetrics().averageCharWidth()
-        self.min_trunc = avg_width * 8  # Minimum size for columns
+        self.min_trunc = avg_width * 12  # Minimum size for columns
         self.max_width = avg_width * 64  # Maximum size for columns
 
         self.setLayout(self.layout)
@@ -1113,7 +1113,7 @@ def _sizeHintForColumn(self, table, col, limit_ms=None):
         max_row = table.model().rowCount()
         lm_start = time.clock()
         lm_row = 64 if limit_ms else max_row
-        max_width = 0
+        max_width = self.min_trunc
         for row in range(max_row):
             v = table.sizeHintForIndex(table.model().index(row, col))
             max_width = max(max_width, v.width())
@@ -1135,7 +1135,7 @@ def _resizeColumnToContents(self, header, data, col, limit_ms):
             width = max(min(hdr_width, self.min_trunc), min(self.max_width,
                         data_width))
         else:
-            width = min(self.max_width, hdr_width)
+            width = max(min(self.max_width, hdr_width), self.min_trunc)
         header.setColumnWidth(col, width)
 
     def _resizeColumnsToContents(self, header, data, limit_ms):
@@ -1194,7 +1194,6 @@ def resizeColumnsToContents(self):
         self._resizeColumnsToContents(self.table_level,
                                       self.table_index, self._max_autosize_ms)
         self._update_layout()
-        self.table_level.resizeColumnsToContents()
 
     def change_bgcolor_enable(self, state):
         """


Test patch: