Repository: spyder-ide/spyder

Issue:
Numpy array copy format
I frequently do copying float precision Numpy array data from variable explore and pasting it to Excel. 
At this time, the number pasted to Excel is recognized in exponential format, is it specification? 
Can you fix it so that it is recognized in numerical form?

Versions and main components
  Spyder Version: 3.1.3
  Python Version: 3.6
  OS: windows 7 pro


Discussion:
Thanks for reporting. @dalthviz, please take a look at this one to see if we can do something about it.
Thank you .

Resolving patch:
diff --git a/spyder/widgets/variableexplorer/arrayeditor.py b/spyder/widgets/variableexplorer/arrayeditor.py
--- a/spyder/widgets/variableexplorer/arrayeditor.py
+++ b/spyder/widgets/variableexplorer/arrayeditor.py
@@ -20,7 +20,7 @@
 from qtpy.compat import from_qvariant, to_qvariant
 from qtpy.QtCore import (QAbstractTableModel, QItemSelection,
                          QItemSelectionRange, QModelIndex, Qt, Slot)
-from qtpy.QtGui import QColor, QCursor, QDoubleValidator
+from qtpy.QtGui import QColor, QCursor, QDoubleValidator, QKeySequence
 from qtpy.QtWidgets import (QAbstractItemDelegate, QApplication, QCheckBox,
                             QComboBox, QDialog, QDialogButtonBox, QGridLayout,
                             QHBoxLayout, QInputDialog, QItemDelegate, QLabel,
@@ -492,7 +492,7 @@ def _sel_to_text(self, cell_range):
             output = io.StringIO()
         try:
             np.savetxt(output, _data[row_min:row_max+1, col_min:col_max+1],
-                       delimiter='\t')
+                       delimiter='\t', fmt=self.model().get_format())
         except:
             QMessageBox.warning(self, _("Warning"),
                                 _("It was not possible to copy values for "


Test patch:
diff --git a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py
--- a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py
+++ b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py
@@ -14,9 +14,9 @@
 import numpy as np
 from numpy.testing import assert_array_equal
 import pytest
+from qtpy.QtCore import Qt
 
 # Local imports
-from spyder.utils.qthelpers import qapplication
 from spyder.widgets.variableexplorer.arrayeditor import ArrayEditor
 
 
@@ -28,9 +28,32 @@ def launch_arrayeditor(data, title="", xlabels=None, ylabels=None):
     dlg.accept()  # trigger slot connected to OK button
     return dlg.get_value()
 
+def setup_arrayeditor(qbot, data, title="", xlabels=None, ylabels=None):
+    """Setups an arrayeditor."""
+    dlg = ArrayEditor()
+    dlg.setup_and_check(data, title, xlabels=xlabels, ylabels=ylabels)    
+    dlg.show()
+    qbot.addWidget(dlg)
+    return dlg
 
 # --- Tests
 # -----------------------------------------------------------------------------
+def test_arrayeditor_format(qtbot):
+    """Changes the format of the array and validates its selected content."""
+    arr = np.array([1, 2, 3], dtype=np.float32)
+    dlg = setup_arrayeditor(qtbot, arr, "test array float32")
+    qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier)
+    qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier)
+    contents = dlg.arraywidget.view._sel_to_text(dlg.arraywidget.view.selectedIndexes())
+    assert contents == "1.000\n2.000\n"
+    dlg.arraywidget.view.model().set_format("%.18e")
+    assert dlg.arraywidget.view.model().get_format() == "%.18e"
+    qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier)
+    qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier)
+    contents = dlg.arraywidget.view._sel_to_text(dlg.arraywidget.view.selectedIndexes())
+    assert contents == "1.000000000000000000e+00\n2.000000000000000000e+00\n"
+    
+
 def test_arrayeditor_with_string_array(qtbot):
     arr = np.array(["kjrekrjkejr"])
     assert arr == launch_arrayeditor(arr, "string array")