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

rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 1c7d1f049bc fix(utils): return None from cast_to_num for non-decimal 
digit strings (#44615)
1c7d1f049bc is described below

commit 1c7d1f049bce198966189dd29332cb3e3ca83977
Author: Devansh Bhargava <[email protected]>
AuthorDate: Fri Sep 25 02:05:43 2026 +0530

    fix(utils): return None from cast_to_num for non-decimal digit strings 
(#44615)
---
 superset/utils/core.py              |  2 +-
 tests/unit_tests/utils/test_core.py | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/superset/utils/core.py b/superset/utils/core.py
index ba059d9905d..74c382bf096 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -498,7 +498,7 @@ def cast_to_num(value: float | int | str | None) -> float | 
int | None:
         return None
     if isinstance(value, (int, float)):
         return value
-    if value.isdigit():
+    if value.isdecimal():
         return int(value)
     try:
         return float(value)
diff --git a/tests/unit_tests/utils/test_core.py 
b/tests/unit_tests/utils/test_core.py
index 8d3ddff228f..ee040d2205b 100644
--- a/tests/unit_tests/utils/test_core.py
+++ b/tests/unit_tests/utils/test_core.py
@@ -30,6 +30,7 @@ from superset.exceptions import SupersetException
 from superset.utils.core import (
     build_email_attachment,
     cast_to_boolean,
+    cast_to_num,
     check_is_safe_zip,
     DateColumn,
     extract_dataframe_dtypes,
@@ -247,6 +248,24 @@ def test_other_values():
     assert cast_to_boolean(object()) is False
 
 
[email protected](
+    "value, expected",
+    [
+        ("5", 5),
+        ("5.2", 5.2),
+        (" 2", 2.0),
+        (10, 10),
+        (None, None),
+        ("this is not a string", None),
+        # ``str.isdigit()`` is true for these but ``int()`` rejects them
+        ("²", None),
+        ("①", None),
+    ],
+)
+def test_cast_to_num(value: Any, expected: Any) -> None:
+    assert cast_to_num(value) == expected
+
+
 def test_normalize_dttm_col() -> None:
     """
     Tests for the ``normalize_dttm_col`` function.

Reply via email to