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


##########
tests/unit_tests/common/test_dataframe_utils.py:
##########
@@ -48,3 +49,27 @@ def test_is_datetime_series():
             datetime.datetime(2018, 1, 1), datetime.datetime(2018, 2, 1)
         ).to_series()
     )
+
+
+def test_df_metrics_to_num_converts_string_numerics():
+    """Test that string-encoded numeric columns (e.g. from ClickHouse) are 
converted."""
+    query_object = MagicMock()
+    query_object.metric_names = ["sum_col", "mixed_col", "text_col"]
+    df = pd.DataFrame(
+        {
+            "sum_col": pd.array(["100", "200", "300"], dtype=object),
+            "mixed_col": pd.array(["1", "not_a_number", "3"], dtype=object),
+            "text_col": pd.array(["foo", "bar", "baz"], dtype=object),
+            "dim_col": pd.array(["a", "b", "c"], dtype=object),

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Incorrect test data construction</b></div>
   <div id="fix">
   
   Columns created with `pd.array(..., dtype=object)` become `str` dtype in 
DataFrames, not `np.object_`. The implementation at line 57 checks `dtype.type 
== np.object_`, which will never match these columns. Test data must use 
`pd.Series(..., dtype=object)` instead.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```
    --- tests/unit_tests/common/test_dataframe_utils.py
    +++ tests/unit_tests/common/test_dataframe_utils.py
    @@ -57,10 +57,10 @@ def test_df_metrics_to_num_converts_string_numerics():
         query_object.metric_names = ["sum_col", "mixed_col", "text_col"]
         df = pd.DataFrame(
             {
    -            "sum_col": pd.array(["100", "200", "300"], dtype=object),
    -            "mixed_col": pd.array(["1", "not_a_number", "3"], 
dtype=object),
    -            "text_col": pd.array(["foo", "bar", "baz"], dtype=object),
    -            "dim_col": pd.array(["a", "b", "c"], dtype=object),
    +            "sum_col": pd.Series(["100", "200", "300"], dtype=object),
    +            "mixed_col": pd.Series(["1", "not_a_number", "3"], 
dtype=object),
    +            "text_col": pd.Series(["foo", "bar", "baz"], dtype=object),
    +            "dim_col": pd.Series(["a", "b", "c"], dtype=object),
             }
         )
   ```
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #fc4dc1</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