Skip to content

Commit a1c496d

Browse files
committed
fixed LArrayDataAdapter.get_xlabels being slow on large 1D arrays (issue #93)
1 parent e34af80 commit a1c496d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

larray_editor/arrayadapter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def get_xlabels(self):
5151
if self.filtered_data.size == 0 or len(axes) == 0:
5252
return None
5353
else:
54-
return [[label] for label in axes.labels[-1]]
54+
# this is a lazy equivalent of:
55+
# return [(label,) for label in axes.labels[-1]]
56+
return Product([axes.labels[-1]])
5557

5658
def get_ylabels(self):
5759
axes = self.filtered_data.axes

larray_editor/arraymodel.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import numpy as np
44
from larray_editor.utils import (get_font, from_qvariant, to_qvariant, to_text_string,
5-
is_float, is_number, LinearGradient, SUPPORTED_FORMATS, scale_to_01range)
5+
is_float, is_number, LinearGradient, SUPPORTED_FORMATS, scale_to_01range,
6+
Product)
67
from qtpy.QtCore import Qt, QModelIndex, QAbstractTableModel
78
from qtpy.QtGui import QColor
89
from qtpy.QtWidgets import QMessageBox
@@ -132,8 +133,9 @@ def __init__(self, parent=None, data=None, readonly=False, font=None):
132133
def _set_data(self, data, changes=None):
133134
if data is None:
134135
data = [[]]
135-
if not isinstance(data, (list, tuple)):
136-
QMessageBox.critical(self.dialog, "Error", "Expected list or tuple.")
136+
# TODO: use sequence instead
137+
if not isinstance(data, (list, tuple, Product)):
138+
QMessageBox.critical(self.dialog, "Error", "Expected list, tuple or Product")
137139
data = [[]]
138140
self._data = data
139141
self.total_rows = len(data[0])

0 commit comments

Comments
 (0)