eschutho opened a new pull request, #42004:
URL: https://github.com/apache/superset/pull/42004

   ## What
   Production logs showed a high-volume pandas `FutureWarning`:
   
   > The provided callable <function mean/median at 0x...> is currently using 
SeriesGroupBy.mean/median. In a future version of pandas, the provided callable 
will be used directly. To keep current behavior pass the string "mean"/"median" 
instead.
   
   This exact class of warning was previously addressed in #41025, which taught 
`_get_aggregate_funcs` (in `pandas_postprocessing/utils.py`) to pass the string 
operator name (e.g. `"mean"`) instead of a raw numpy callable when possible, 
avoiding the ambiguity pandas warns about.
   
   However, `pandas_postprocessing/boxplot.py` builds its own `operators` dict 
independently and was passing `np.mean` / `np.median` directly as the 
`operator` value. Since `_get_aggregate_funcs` special-cases callables first 
(`if callable(operator): aggfunc = operator`), this bypassed the #41025 fix 
entirely — so every boxplot chart post-processing call kept emitting the 
warning. Boxplot charts are common, which is why this was showing up frequently 
in prod logs.
   
   ## Change
   In `boxplot.py`, pass `"mean"` / `"median"` as string literals instead of 
`np.mean` / `np.median`, so they route through the same string-based path 
`_get_aggregate_funcs` already uses. `np.ma.count` is left untouched, since it 
intentionally differs from pandas' `"count"` (it includes NaNs).
   
   ## No behavior change
   Verified empirically that the string and callable forms produce identical 
output for `mean`/`median` on the currently pinned pandas range 
(`>=2.1.4,<2.4`). Added a regression test that also guards against a real (not 
just cosmetic) divergence: on pandas ≥3.0, `np.median` on a group containing 
NaNs returns `NaN` (no `skipna`), while the `"median"` string aggregator still 
skips NaNs — so this also prevents a silent numeric regression whenever the 
pandas pin is eventually bumped.
   
   ## Test plan
   - Added `test_boxplot_mean_median_no_future_warning` in 
`tests/unit_tests/pandas_postprocessing/test_boxplot.py`: asserts no 
`FutureWarning` is raised and that `mean`/`median` values match a plain 
`df.groupby(...).agg(["mean", "median"])` call.
   - Ran the full `tests/unit_tests/pandas_postprocessing/` suite locally (108 
tests, all passing).
   - Ran `ruff check` / `ruff format` and `mypy` on the changed file — no new 
issues introduced (two pre-existing, unrelated mypy errors on lines 103-104 
remain untouched).


-- 
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