Skip to content

Commit

Permalink
fix: preserve whitespace in data table (marimo-team#1894)
Browse files Browse the repository at this point in the history
So NLP-ers and data scientists can see true underlying data.
  • Loading branch information
akshayka committed Jul 26, 2024
1 parent a7f647c commit 1300874
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions frontend/src/components/data-table/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ const DataTableInternal = <TData,>({
return;
}

// whitespace-pre so that strings with different whitespace look
// different
return table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
return (
<TableHead
key={header.id}
className="h-auto min-h-10 whitespace-nowrap align-baseline"
className="h-auto min-h-10 whitespace-pre align-baseline"
>
{header.isPlaceholder
? null
Expand Down Expand Up @@ -181,7 +183,7 @@ const DataTableInternal = <TData,>({
<TableCell
key={cell.id}
className={cn(
"whitespace-nowrap truncate max-w-[300px]",
"whitespace-pre truncate max-w-[300px]",
cell.column.getColumnWrapping &&
cell.column.getColumnWrapping() === "wrap" &&
"whitespace-pre-wrap min-w-[200px]",
Expand Down
1 change: 1 addition & 0 deletions marimo/_smoke_tests/markdown_size.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2024 Marimo. All rights reserved.
import marimo

__generated_with = "0.7.12"
Expand Down
8 changes: 6 additions & 2 deletions tests/_plugins/ui/_impl/tables/test_pandas_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setUp(self) -> None:
# Integer
"A": [1, 2, 3],
# String
"B": ["a", "b", "c"],
"B": ["a", "b", " b"],
# Float
"C": [1.0, 2.0, 3.0],
# Boolean
Expand Down Expand Up @@ -345,7 +345,11 @@ def test_sort_values_with_index(self) -> None:

def test_get_unique_column_values(self) -> None:
column = "B"
assert self.manager.get_unique_column_values(column) == ["a", "b", "c"]
assert self.manager.get_unique_column_values(column) == [
"a",
"b",
" b",
]

def test_search(self) -> None:
import pandas as pd
Expand Down

0 comments on commit 1300874

Please sign in to comment.