Skip to content

Commit

Permalink
Merge from 3.x: PR #5259
Browse files Browse the repository at this point in the history
Fixes #5254
  • Loading branch information
ccordoba12 committed Sep 16, 2017
2 parents f4ce24c + 58a1330 commit 5c624be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
21 changes: 14 additions & 7 deletions spyder/widgets/variableexplorer/arrayeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,24 @@ def data(self, index, role=Qt.DisplayRole):
if value is np.ma.masked:
return ''
else:
return to_qvariant(self._format % value)
try:
return to_qvariant(self._format % value)
except TypeError:
self.readonly = True
return repr(value)
elif role == Qt.TextAlignmentRole:
return to_qvariant(int(Qt.AlignCenter|Qt.AlignVCenter))
elif role == Qt.BackgroundColorRole and self.bgcolor_enabled \
and value is not np.ma.masked:
hue = self.hue0+\
self.dhue*(float(self.vmax)-self.color_func(value)) \
/(float(self.vmax)-self.vmin) #float convert to handle bool arrays
hue = float(np.abs(hue))
color = QColor.fromHsvF(hue, self.sat, self.val, self.alp)
return to_qvariant(color)
try:
hue = (self.hue0 +
self.dhue * (float(self.vmax) - self.color_func(value))
/ (float(self.vmax) - self.vmin))
hue = float(np.abs(hue))
color = QColor.fromHsvF(hue, self.sat, self.val, self.alp)
return to_qvariant(color)
except TypeError:
return to_qvariant()
elif role == Qt.FontRole:
return to_qvariant(get_font(font_size_delta=DEFAULT_SMALL_DELTA))
return to_qvariant()
Expand Down
12 changes: 12 additions & 0 deletions spyder/widgets/variableexplorer/tests/test_arrayeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ def setup_arrayeditor(qbot, data, title="", xlabels=None, ylabels=None):

# --- Tests
# -----------------------------------------------------------------------------
def test_type_errors(qtbot):
"""Verify that we don't get a TypeError for certain structured arrays.
Fixes issue 5254.
"""
arr = np.ones(2, dtype=[('X', 'f8', (2,10)), ('S', 'S10')])
dlg = setup_arrayeditor(qtbot, arr)
qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier)
contents = dlg.arraywidget.model.get_value(dlg.arraywidget.model.index(0, 0))
assert_array_equal(contents, np.ones(10))


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)
Expand Down

0 comments on commit 5c624be

Please sign in to comment.