Skip to content

Commit 79c1394

Browse files
authored
use searched manager instead of manager for column charts get value counts (#7033)
## 📝 Summary <!-- Provide a concise summary of what this pull request is addressing. If this PR fixes any issues, list them here by number (e.g., Fixes #123). --> For column header charts for string/categories, previously even with a filter, it would still calculate value_counts based on all the rows. Leading to the chart not changing. This fixes ensures the frontend chart changes according to filters. <img src="https://github.com/user-attachments/assets/e991c5da-ec1b-4a4b-b46e-be476889d0d7" height=300 /> ## 🔍 Description of Changes <!-- Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [x] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected.
1 parent 8fbef8b commit 79c1394

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

marimo/_plugins/ui/_impl/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ def _get_value_counts(
10601060
LOGGER.warning("Total rows and size is not valid")
10611061
return []
10621062

1063-
top_k_rows = self._manager.calculate_top_k_rows(column, size)
1063+
top_k_rows = self._searched_manager.calculate_top_k_rows(column, size)
10641064
if len(top_k_rows) == 0:
10651065
return []
10661066

tests/_plugins/ui/_impl/test_table.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,18 @@ def test_with_smaller_limit(self, table: ui.table) -> None:
10881088
ValueCount(value="others", count=3),
10891089
]
10901090

1091+
def test_with_search(self, table: ui.table) -> None:
1092+
result = table._search(
1093+
SearchTableArgs(query="1", page_size=10, page_number=0)
1094+
)
1095+
rows = table._searched_manager.get_num_rows(force=True)
1096+
assert rows is not None
1097+
assert result.total_rows == 2
1098+
value_counts = table._get_value_counts(
1099+
column="repeat", size=2, total_rows=rows
1100+
)
1101+
assert value_counts == [ValueCount(value="1", count=2)]
1102+
10911103

10921104
def test_table_with_frozen_columns() -> None:
10931105
data = {

0 commit comments

Comments
 (0)