Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: case sensitivity of uppercase searches (#3131)

Myles Scolnick081f703e1ee4
diff --git a/marimo/_plugins/ui/_impl/tables/narwhals_table.py b/marimo/_plugins/ui/_impl/tables/narwhals_table.py
index d38f891556..db3150c519 100644
--- a/marimo/_plugins/ui/_impl/tables/narwhals_table.py
+++ b/marimo/_plugins/ui/_impl/tables/narwhals_table.py
@@ -137,10 +137,11 @@ class NarwhalsTableManager(
expressions: list[Any] = []
for column, dtype in self.nw_schema.items():
if dtype == nw.String:
- expressions.append(nw.col(column).str.contains(query))
+ expressions.append(nw.col(column).str.contains(f"(?i){query}"))
elif dtype == nw.List(nw.String):
+ # TODO: Narwhals doesn't support list.contains
# expressions.append(
- # nw.col(column).cast(nw.String).sum().str.contains(query)
+ # nw.col(column).list.contains(query)
# )
pass
elif (
diff --git a/marimo/_plugins/ui/_impl/tables/polars_table.py b/marimo/_plugins/ui/_impl/tables/polars_table.py
index a1494147e1..06991042e1 100644
--- a/marimo/_plugins/ui/_impl/tables/polars_table.py
+++ b/marimo/_plugins/ui/_impl/tables/polars_table.py
@@ -142,7 +142,9 @@ class PolarsTableManagerFactory(TableManagerFactory):
expressions: list[pl.Expr] = []
for column, dtype in self.schema.items():
if dtype == pl.String:
- expressions.append(pl.col(column).str.contains(query))
+ expressions.append(
+ pl.col(column).str.contains(f"(?i){query}")
+ )
elif dtype == pl.List(pl.Utf8):
expressions.append(pl.col(column).list.contains(query))
elif (
diff --git a/tests/_plugins/ui/_impl/tables/test_narwhals.py b/tests/_plugins/ui/_impl/tables/test_narwhals.py
index cd184c1b3c..23f0d88642 100644
--- a/tests/_plugins/ui/_impl/tables/test_narwhals.py
+++ b/tests/_plugins/ui/_impl/tables/test_narwhals.py
@@ -380,6 +380,7 @@ class TestNarwhalsTableManagerFactory(unittest.TestCase):
"C": [True, False, True],
"D": [["zz", "yyy"], [], []],
"E": [1.1, 2.2, 3.3],
+ "G": ["U", "T", "V"],
}
)
manager = NarwhalsTableManager.from_dataframe(df)
@@ -387,6 +388,9 @@ class TestNarwhalsTableManagerFactory(unittest.TestCase):
assert manager.search("foo").get_num_rows() == 1
# Contains
assert manager.search("a").get_num_rows() == 2
+ # Case insensitive
+ assert manager.search("v").get_num_rows() == 1
+ assert manager.search("V").get_num_rows() == 1
# Case insensitive / boolean
assert manager.search("true").get_num_rows() == 2
# Overmatch
diff --git a/tests/_plugins/ui/_impl/tables/test_pandas_table.py b/tests/_plugins/ui/_impl/tables/test_pandas_table.py
index 005057b18f..8d070c79f2 100644
--- a/tests/_plugins/ui/_impl/tables/test_pandas_table.py
+++ b/tests/_plugins/ui/_impl/tables/test_pandas_table.py
@@ -468,13 +468,30 @@ class TestPandasTableManager(unittest.TestCase):
"A": [1, 2, 3],
"B": ["foo", "bar", "baz"],
"C": [True, False, True],
+ "D": [["zz", "yyy"], [], []],
+ "E": [1.1, 2.2, 3.3],
+ "G": ["U", "T", "V"],
}
)
manager = self.factory.create()(df)
+ # Exact match
assert manager.search("foo").get_num_rows() == 1
+ # Contains
assert manager.search("a").get_num_rows() == 2
+ # Case insensitive
+ assert manager.search("v").get_num_rows() == 1
+ assert manager.search("V").get_num_rows() == 1
+ # Case insensitive / boolean
assert manager.search("true").get_num_rows() == 2
+ # Overmatch
assert manager.search("food").get_num_rows() == 0
+ # Int (exact match)
+ assert manager.search("1").get_num_rows() == 1
+ # Float (exact match)
+ assert manager.search("1.1").get_num_rows() == 1
+ # List (exact match)
+ assert manager.search("yyy").get_num_rows() == 0
+ assert manager.search("y").get_num_rows() == 0
def test_apply_formatting_does_not_modify_original_data(self) -> None:
original_data = self.data.copy()
diff --git a/tests/_plugins/ui/_impl/tables/test_polars_table.py b/tests/_plugins/ui/_impl/tables/test_polars_table.py
index 10b78d9f58..1de1c4a5d8 100644
--- a/tests/_plugins/ui/_impl/tables/test_polars_table.py
+++ b/tests/_plugins/ui/_impl/tables/test_polars_table.py
@@ -411,6 +411,7 @@ class TestPolarsTableManagerFactory(unittest.TestCase):
"C": [True, False, True],
"D": [["zz", "yyy"], [], []],
"E": [1.1, 2.2, 3.3],
+ "G": ["U", "T", "V"],
}
)
manager = self.factory.create()(df)
@@ -418,6 +419,9 @@ class TestPolarsTableManagerFactory(unittest.TestCase):
assert manager.search("foo").get_num_rows() == 1
# Contains
assert manager.search("a").get_num_rows() == 2
+ # Case insensitive
+ assert manager.search("v").get_num_rows() == 1
+ assert manager.search("V").get_num_rows() == 1
# Case insensitive / boolean
assert manager.search("true").get_num_rows() == 2
# Overmatch