This is an automated email from the ASF dual-hosted git repository.

skrawcz pushed a commit to branch stefan/fix-unit-tests
in repository https://gitbox.apache.org/repos/asf/hamilton.git

commit 65d0d7ec11695df975894a2abbb527eadc1a1d81
Author: Stefan Krawczyk <[email protected]>
AuthorDate: Mon Dec 29 22:32:51 2025 +1100

    Updates polars tests
---
 tests/plugins/test_polars_extensions.py              |  9 +--------
 ui/sdk/src/hamilton_sdk/tracking/polars_col_stats.py |  3 +++
 ui/sdk/src/hamilton_sdk/tracking/polars_stats.py     |  5 +++--
 ui/sdk/tests/tracking/test_polars_stats.py           | 10 +++++-----
 4 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/tests/plugins/test_polars_extensions.py 
b/tests/plugins/test_polars_extensions.py
index 1bec4494..796e413c 100644
--- a/tests/plugins/test_polars_extensions.py
+++ b/tests/plugins/test_polars_extensions.py
@@ -201,12 +201,5 @@ def test_polars_spreadsheet(df: pl.DataFrame, tmp_path: 
pathlib.Path) -> None:
 
 def test_getting_type_hints_spreadsheetwriter():
     """Tests that types can be resolved at run time."""
-
-    local_namespace = {}
-    if sys.version_info.major == 3 and sys.version_info.minor > 8:
-        from polars.selectors import Selector
-
-        local_namespace = {"Selector": Selector}
-
-    type_hints = typing.get_type_hints(PolarsSpreadsheetWriter, 
localns=local_namespace)
+    type_hints = typing.get_type_hints(PolarsSpreadsheetWriter)
     assert type_hints["workbook"] == typing.Union[Workbook, io.BytesIO, 
pathlib.Path, str]
diff --git a/ui/sdk/src/hamilton_sdk/tracking/polars_col_stats.py 
b/ui/sdk/src/hamilton_sdk/tracking/polars_col_stats.py
index e1048567..086cd5d2 100644
--- a/ui/sdk/src/hamilton_sdk/tracking/polars_col_stats.py
+++ b/ui/sdk/src/hamilton_sdk/tracking/polars_col_stats.py
@@ -48,6 +48,9 @@ def zeros(col: pl.Series) -> int:
     except ValueError:
         # e.g. comparing datetime
         return 0
+    except NotImplementedError:
+        # Polars 1.0+ raises NotImplementedError for Date types
+        return 0
     if str(result) == "NotImplemented":
         return 0
     return result.sum()
diff --git a/ui/sdk/src/hamilton_sdk/tracking/polars_stats.py 
b/ui/sdk/src/hamilton_sdk/tracking/polars_stats.py
index 38357c8d..d9332855 100644
--- a/ui/sdk/src/hamilton_sdk/tracking/polars_stats.py
+++ b/ui/sdk/src/hamilton_sdk/tracking/polars_stats.py
@@ -18,6 +18,7 @@
 from typing import Any, Dict
 
 import polars as pl
+from polars import selectors
 
 if not hasattr(pl, "Series"):
     raise ImportError("Polars is not installed")
@@ -54,10 +55,10 @@ def _compute_stats(df: pl.DataFrame) -> Dict[str, Dict[str, 
Any]]:
     """
     category_types = df.select([pl.col(pl.Categorical)])
     string_types = df.select([pl.col(pl.Utf8)])
-    numeric_types = df.select([pl.col(pl.NUMERIC_DTYPES)])
+    numeric_types = df.select(selectors.numeric())
     bool_types = df.select([pl.col(pl.Boolean)])
     # df.select([pl.col(pl.Object)])
-    date_types = df.select([pl.col(pl.TEMPORAL_DTYPES)])
+    date_types = df.select(selectors.temporal())
     # get all other columns that have not been selected
     # df.select(
     #     ~cs.by_dtype([pl.Categorical, pl.Utf8, pl.Boolean, pl.Object])
diff --git a/ui/sdk/tests/tracking/test_polars_stats.py 
b/ui/sdk/tests/tracking/test_polars_stats.py
index a8a9d43a..f0f02454 100644
--- a/ui/sdk/tests/tracking/test_polars_stats.py
+++ b/ui/sdk/tests/tracking/test_polars_stats.py
@@ -10,7 +10,7 @@ def test_compute_stats_df():
             "b": ["a", "b", "c", "d", "e"],
             "c": [True, False, True, False, True],
             "d": [1.0, 2.0, 3.0, 4.0, 5.0],
-            "e": pl.Series(["a", "b", "c", "d", "e"], dtype=pl.Categorical),
+            "e": pl.Series(["a", "a", "b", "c", "d"], dtype=pl.Categorical),
             "f": pl.Series(["a", "b", "c", "d", "e"], dtype=pl.Utf8),
             "g": pl.Series(["a", "b", "c", "d", "e"], dtype=pl.Object),
             "h": pl.Series(
@@ -100,15 +100,15 @@ def test_compute_stats_df():
             "e": {
                 "base_data_type": "category",
                 "count": 5,
-                "data_type": "Categorical(ordering='physical')",
-                "domain": {"a": 1, "b": 1, "c": 1, "d": 1, "e": 1},
+                "data_type": "Categorical",
+                "domain": {"a": 2, "b": 1, "c": 1, "d": 1},
                 "empty": 0,
                 "missing": 0,
                 "name": "e",
                 "pos": 4,
-                "top_freq": 1,
+                "top_freq": 2,
                 "top_value": "a",
-                "unique": 5,
+                "unique": 4,
             },
             "f": {
                 "avg_str_len": 1.0,

Reply via email to