From 26fe0ca5b59cd72b139dcb0018c471b7f29746af Mon Sep 17 00:00:00 2001 From: Roman-Kornev <119343173+Roman-Kornev@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:30:27 +0100 Subject: [PATCH] Fix: DO-3658: Fix Table non-unique index values, fix sorting by unnamed index (#363) --- packages/dara-core/changelog.md | 5 +++++ .../dara-core/dara/core/interactivity/filtering.py | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/dara-core/changelog.md b/packages/dara-core/changelog.md index eb8bf090..92b5355d 100644 --- a/packages/dara-core/changelog.md +++ b/packages/dara-core/changelog.md @@ -2,6 +2,11 @@ title: Changelog --- +## NEXT + +- Fixed a crash in `Table` pagination where rows containing non-unique index values would cause a slicing error. +- Fixed an issue in `Table` where sorting by an unnamed index would not work. + ## 1.12.6 - Fix an issue where LRU cache could result in a `KeyError` diff --git a/packages/dara-core/dara/core/interactivity/filtering.py b/packages/dara-core/dara/core/interactivity/filtering.py index c1e39966..a1a0e863 100644 --- a/packages/dara-core/dara/core/interactivity/filtering.py +++ b/packages/dara-core/dara/core/interactivity/filtering.py @@ -274,14 +274,16 @@ def apply_filters( order_by = order_by[1:] ascending = False - new_data = new_data.sort_values( - by=re.sub(COLUMN_PREFIX_REGEX, '', order_by), ascending=ascending, inplace=False - ) + col = re.sub(COLUMN_PREFIX_REGEX, '', order_by) + if col == 'index': + new_data = new_data.sort_index(ascending=ascending, inplace=False) + else: + new_data = new_data.sort_values(by=col, ascending=ascending, inplace=False) # PAGINATE start_index = pagination.offset if pagination.offset is not None else 0 stop_index = start_index + pagination.limit if pagination.limit is not None else total_count - new_data = new_data[start_index:stop_index] + new_data = new_data.iloc[start_index:stop_index] return new_data, total_count