bito-code-review[bot] commented on code in PR #40222:
URL: https://github.com/apache/superset/pull/40222#discussion_r3270771558


##########
tests/unit_tests/semantic_layers/mapper_test.py:
##########
@@ -2741,3 +2829,205 @@ def test_get_group_limit_filters_no_granularity(
 
     # Should return None - no granularity means no time filters added
     assert result is None
+
+
+# ---------------------------------------------------------------------------
+# _coerce_scalar_filter_value: per-dtype branches
+# ---------------------------------------------------------------------------
+
+
+def _dim(dtype: pa.DataType, name: str = "d") -> Dimension:
+    return Dimension(name, name, dtype, name, name.capitalize())
+
+
+def test_coerce_none_returns_none() -> None:
+    assert _coerce_scalar_filter_value(None, _dim(pa.int64())) is None
+
+
+def test_coerce_unsupported_dtype_passes_through() -> None:
+    # utf8 (and any dtype not branched in the function) returns the value 
as-is.
+    assert _coerce_scalar_filter_value("abc", _dim(pa.utf8())) == "abc"
+
+
[email protected](
+    "raw,expected",
+    [
+        (True, True),
+        (False, False),
+        (1, True),
+        (0, False),
+        (1.0, True),
+        (0.0, False),
+        ("true", True),
+        ("T", True),
+        (" 1 ", True),
+        ("yes", True),
+        ("Y", True),
+        ("on", True),
+        ("false", False),
+        ("F", False),
+        ("0", False),
+        ("no", False),
+        ("N", False),
+        ("off", False),
+    ],
+)
+def test_coerce_boolean(raw: Any, expected: bool) -> None:
+    assert _coerce_scalar_filter_value(raw, _dim(pa.bool_())) is expected
+
+
[email protected]("raw", ["maybe", 2, 0.5, -1])
+def test_coerce_boolean_invalid_raises(raw: Any) -> None:
+    with pytest.raises(ValueError, match="Invalid boolean value"):
+        _coerce_scalar_filter_value(raw, _dim(pa.bool_()))
+
+
+def test_coerce_integer_passthrough() -> None:
+    assert _coerce_scalar_filter_value(42, _dim(pa.int64())) == 42
+
+
+def test_coerce_integer_accepts_integer_valued_float() -> None:
+    # JSON round-trips can turn an int into ``42.0``; accept losslessly.
+    assert _coerce_scalar_filter_value(42.0, _dim(pa.int64())) == 42
+
+
+def test_coerce_integer_rejects_bool() -> None:
+    # bool is a subclass of int; we explicitly reject it.
+    with pytest.raises(ValueError, match="Invalid integer value"):
+        _coerce_scalar_filter_value(True, _dim(pa.int64()))
+
+
+def test_coerce_integer_rejects_non_integer_float() -> None:
+    with pytest.raises(ValueError, match="Invalid integer value"):
+        _coerce_scalar_filter_value(1.5, _dim(pa.int64()))
+
+
+def test_coerce_integer_rejects_other_types() -> None:
+    with pytest.raises(ValueError, match="Invalid integer value"):
+        _coerce_scalar_filter_value([1], _dim(pa.int64()))
+
+
[email protected](
+    "dtype",
+    [pa.float64(), pa.decimal128(10, 2)],
+)
+def test_coerce_floating_or_decimal(dtype: pa.DataType) -> None:
+    assert _coerce_scalar_filter_value(1, _dim(dtype)) == 1.0
+    assert _coerce_scalar_filter_value(1.5, _dim(dtype)) == 1.5
+    assert _coerce_scalar_filter_value(" 2.5 ", _dim(dtype)) == 2.5
+
+
+def test_coerce_floating_rejects_bool() -> None:
+    with pytest.raises(ValueError, match="Invalid numeric value"):
+        _coerce_scalar_filter_value(True, _dim(pa.float64()))
+
+
+def test_coerce_floating_invalid_string_raises() -> None:
+    with pytest.raises(ValueError, match="Invalid numeric value"):
+        _coerce_scalar_filter_value("not-a-number", _dim(pa.float64()))
+
+
+def test_coerce_floating_rejects_other_types() -> None:
+    with pytest.raises(ValueError, match="Invalid numeric value"):
+        _coerce_scalar_filter_value([1.0], _dim(pa.float64()))
+
+
+def test_coerce_date_from_datetime() -> None:
+    out = _coerce_scalar_filter_value(datetime(2025, 1, 2, 12, 0), 
_dim(pa.date32()))

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>datetime called without tzinfo argument</b></div>
   <div id="fix">
   
   Add `tzinfo` argument to `datetime()` call or use `datetime.now(tz=...)` for 
timezone-aware datetime objects.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
    
   def test_coerce_date_from_datetime() -> None:
       out = _coerce_scalar_filter_value(datetime(2025, 1, 2, 12, 0, 
tzinfo=timezone.utc), _dim(pa.date32()))
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #aded82</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to