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

   ## Decisions made that were not in the instructions
   
   - The string-operator path and the boxplot callers were **already fixed on 
`master`** (PRs #41025 and #42272 introduced `_PANDAS_STRING_AGGREGATORS` and 
switched boxplot to string operators). The one remaining source of this warning 
is the *callable-operator* branch of `_get_aggregate_funcs`, so this fix 
targets that branch (mapping bare numpy callables → string names). It's the 
same call site (`aggregate.py:46`) and the same warning class the report 
describes. No new mapping structures were introduced — the existing 
`NUMPY_FUNCTIONS` and `_PANDAS_STRING_AGGREGATORS` are reused.
   
   ### SUMMARY
   
   A live production `FutureWarning` was surfaced via Datadog at 
`superset/utils/pandas_postprocessing/aggregate.py:46`:
   
   ```
   FutureWarning: The provided callable <function median at 0x...> is currently 
using SeriesGroupBy.median. In a future version of pandas, the provided 
callable will be used directly. To keep current behavior pass the string 
"median" instead.
   ```
   
   `_get_aggregate_funcs` has two operator branches. The string-operator branch 
already maps common operators to pandas string names 
(`_PANDAS_STRING_AGGREGATORS`) to avoid this warning, but the 
**callable-operator** branch forwarded a bare numpy callable (e.g. `np.median`) 
straight through to `GroupBy.agg`, where pandas maps it to its own 
`SeriesGroupBy.median` and raises the `FutureWarning`.
   
   This PR adds a reverse lookup (`_STRING_AGGREGATOR_BY_CALLABLE`), built by 
filtering the existing `NUMPY_FUNCTIONS` down to the callables whose names are 
in `_PANDAS_STRING_AGGREGATORS`, and swaps such callables for their string name 
before calling `.agg()`.
   
   ### BEFORE/AFTER
   
   - **Before:** a bare-callable operator such as `np.median` / `np.mean` / 
`np.sum` emits the `FutureWarning`.
   - **After:** no warning; identical aggregation results and dtypes.
   
   **No behavior change:** only the *representation* of the aggregator changes 
(numpy callable → its equivalent pandas string). The mapped strings produce 
identical values and dtypes (verified for `median`, `mean`, `sum`, `min`, 
`max`, `std`, `var`, `prod`). Non-mapped callables (closures, `np.ma.count`), 
string operators, and the `partial(func, **options)` path are all left 
untouched.
   
   ### TESTING INSTRUCTIONS
   
   ```
   pytest tests/unit_tests/pandas_postprocessing/test_aggregate.py
   ```
   
   Adds `test_aggregate_callable_operator_avoids_future_warning`, which runs 
under `warnings.simplefilter("error", FutureWarning)` (so the 
previously-emitted warning would fail the test) and asserts unchanged values 
for `np.median`, `np.mean`, and `np.sum` operators.
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


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