Repository: spyder-ide/spyder

Issue:
Resize in dataframe viewer does not honor column name length
## Problem Description

In Spyder 4.0.0beta3, when viewing pandas data frames in the variable explorer, I find that the "resize" functionality only honors the width of the actual contents of a column, not the column name. So if the column name is long, it will get clipped and not quite visible.

Interestingly, in all versions of Spyder 3, this is a non-issue: the display width of the column takes into account column name as well. (This is also the expected behavior in Microsoft Excel and/or Google Spreadsheet too.)

### What steps reproduce the problem?

1. Run the following codes:
```python
import pandas as pd
df = pd.DataFrame({'col1': [1, 2, 3], 'column_with_a_long_name': [2, 3, 4]})
```
2. Open `df` in the variable explorer, and click the "resize" button

### What is the expected output? What do you see instead?

The second column's name ("column_with_a_long_name") should not be clipped.

## 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: Spyder 4.0.0beta4
* Python version: 3.7.3
* Qt version: 5.9.6
* PyQt version: 5.9.2
* Operating System name/version: Linux 4.15.10-55-generic




Discussion:
@dalthviz, please take a look at this one.
Hi @ccordoba12 , a somewhat unrelated question: Spyder 4 seems to be some kind of a rewrite parallel to Spyder 3. Is it true? I am just curious what you and your team's vision for these two versions is. Thanks!
In Spyder 4 we replaced a lot of things present in Spyder 3 (e.g. the entire code completion architecture used in our editor) and improved several other things (e.g. our dataframe viewer, to support multi-indexes).

So I wouldn't say Spyder 4 is a complete rewrite, it's just a new major version that adds a lot of new stuff. And due to those additions, things cannot be working as they used to in Spyder 3.
Thanks for the reply! 

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
@@ -1259,11 +1259,16 @@ def get_value(self):
 
     def _update_header_size(self):
         """Update the column width of the header."""
+        self.table_header.resizeColumnsToContents()
         column_count = self.table_header.model().columnCount()
         for index in range(0, column_count):
             if index < column_count:
                 column_width = self.dataTable.columnWidth(index)
-                self.table_header.setColumnWidth(index, column_width)
+                header_width = self.table_header.columnWidth(index)
+                if column_width > header_width:
+                    self.table_header.setColumnWidth(index, column_width)
+                else:
+                    self.dataTable.setColumnWidth(index, header_width)
             else:
                 break
 


Test patch:
diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py
--- a/spyder/app/tests/test_mainwindow.py
+++ b/spyder/app/tests/test_mainwindow.py
@@ -1822,7 +1822,8 @@ def test_custom_layouts(main_window, qtbot):
                                 print(widget)  # spyder: test-skip
                                 assert widget.isVisible()
 
-# @pytest.mark.slow
+
+@pytest.mark.slow
 @flaky(max_runs=3)
 def test_save_on_runfile(main_window, qtbot):
     """Test that layout are showing the expected widgets visible."""
@@ -1848,7 +1849,7 @@ def test_save_on_runfile(main_window, qtbot):
     os.remove(test_file_copy)
 
 
-# @pytest.mark.slow
+@pytest.mark.slow
 def test_pylint_follows_file(qtbot, tmpdir, main_window):
     """Test that file editor focus change updates pylint combobox filename."""
     for plugin in main_window.thirdparty_plugins:
@@ -1886,6 +1887,8 @@ def test_pylint_follows_file(qtbot, tmpdir, main_window):
         assert fname == pylint_plugin.get_filename()
 
 
+@pytest.mark.slow
+@flaky(max_runs=3)
 def test_report_comms_error(qtbot, main_window):
     """Test if a comms error is correctly displayed."""
     CONF.set('main', 'show_internal_errors', True)