Skip to content

Commit 1cdb0f9

Browse files
committed
PERF: fixed performance issue on large Pandas DataFrames
1 parent 8eb51f7 commit 1cdb0f9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

larray_editor/arrayadapter.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,17 @@ def get_hlabels_values(self, start, stop):
17481748
return [index.values]
17491749

17501750
def get_values(self, h_start, v_start, h_stop, v_stop):
1751-
return self.sorted_data.iloc[v_start:v_stop, h_start:h_stop].values
1751+
# Sadly, as of Pandas 2.2.3, the previous version of this code:
1752+
# df.iloc[v_start:v_stop, h_start:h_stop].values
1753+
# first copies all mentioned columns in their entirety, then take the
1754+
# subset of the rows (then converts to a numpy array)
1755+
# As a workaround, we first take each *single* column in its entirety
1756+
# which, in most case, is a view, then take the row slice
1757+
# (then recombine using numpy stack)
1758+
df = self.sorted_data
1759+
columns = [df.iloc[:, i].values for i in range(h_start, h_stop)]
1760+
chunks = [col[v_start:v_stop] for col in columns]
1761+
return np.stack(chunks, axis=1, dtype=object)
17521762

17531763
def can_sort_hlabel(self, row_idx, col_idx):
17541764
# allow sorting on columns but not rows

0 commit comments

Comments
 (0)