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

eschutho pushed a commit to branch fix/pandas-replace-inf-downcast-warning
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 07747d39e081dbd3f1786c5a64b30d71169f5ed2
Author: Elizabeth Thompson <[email protected]>
AuthorDate: Fri Oct 2 16:06:57 2026 +0000

    fix(models): avoid global pandas option; use mask+infer_objects in 
normalize_df
    
    pd.option_context mutates process-global pandas state and is not
    thread-safe. Use DataFrame.mask(...).infer_objects() instead, which
    emits no warning and yields identical dtypes.
    
    Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
 superset/models/helpers.py              | 8 +++-----
 tests/unit_tests/models/helpers_test.py | 2 ++
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index 5254b926e04..a10a0e49ea9 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -2635,11 +2635,9 @@ class ExploreMixin:  # pylint: 
disable=too-many-public-methods
         if getattr(self, "enforce_numerical_metrics", True):
             dataframe_utils.df_metrics_to_num(df, query_object)
 
-        # Opt out of pandas' deprecated silent downcasting inside ``replace`` 
and
-        # then downcast explicitly, which keeps the existing dtype behavior.
-        with pd.option_context("future.no_silent_downcasting", True):
-            df.replace([np.inf, -np.inf], np.nan, inplace=True)
-        df = df.infer_objects(copy=False)
+        # ``mask`` + ``infer_objects`` rather than ``replace``, which emits a
+        # FutureWarning about deprecated silent downcasting on object columns.
+        df = df.mask(df.isin([np.inf, -np.inf])).infer_objects()
 
         return df
 
diff --git a/tests/unit_tests/models/helpers_test.py 
b/tests/unit_tests/models/helpers_test.py
index 0f6a88e348e..f07e3fe46d6 100644
--- a/tests/unit_tests/models/helpers_test.py
+++ b/tests/unit_tests/models/helpers_test.py
@@ -4136,6 +4136,7 @@ def 
test_normalize_df_replaces_infinity_without_downcasting_warning() -> None:
     df = pd.DataFrame(
         {
             "metric": pd.Series([1.0, np.inf, -np.inf, 2.0], dtype=object),
+            "count": pd.Series([1, 2, -np.inf, 4], dtype=object),
             "label": ["a", "b", "c", "d"],
         }
     )
@@ -4146,6 +4147,7 @@ def 
test_normalize_df_replaces_infinity_without_downcasting_warning() -> None:
 
     assert result["metric"].dtype == np.float64
     assert result["metric"].isna().tolist() == [False, True, True, False]
+    assert result["count"].dtype == np.float64
     assert result["label"].dtype == object
 
 

Reply via email to