sushu0 opened a new issue, #45466:
URL: https://github.com/apache/superset/issues/45466

   ### Bug description
   
   The `compare` pandas post-processing operation raises 
`decimal.DivisionByZero` (or `decimal.InvalidOperation` for 0/0) when 
percentage or ratio comparisons receive Decimal columns with a zero baseline. 
The same operation with float columns completes and returns the existing 
infinity/NaN result. Both branches convert their result to float, but that 
conversion happens **after** Decimal division has already raised.
   
   This affects raw-column post-processing requests: `columns: ["current", 
"previous"]`, `metrics: []`, followed by `compare`. `ExploreMixin.normalize_df` 
only coerces metric columns to numbers, so raw SQL DECIMAL columns remain 
Decimal objects. I am not claiming that the usual UI time-comparison metric 
path is affected; those metric columns are normally converted before 
post-processing.
   
   Reproduction against master `99ecfe5801c4cbb79eedd475003b134b6ba7ff28`, 
using the real imported operation:
   
   ```python
   from decimal import Decimal
   import pandas as pd
   from superset.constants import PandasPostprocessingCompare as PPC
   from superset.utils import pandas_postprocessing as pp
   
   df = pd.DataFrame({"current": [Decimal("10")], "previous": [Decimal("0")]})
   pp.compare(
       df,
       source_columns=["current"],
       compare_columns=["previous"],
       compare_type=PPC.RAT,  # PPC.PCT also fails
   )
   ```
   
   Traceback ends at `superset/utils/pandas_postprocessing/compare.py:73`, 
before `.astype(float)`:
   
   ```text
   diff_df = (s_df / c_df).astype(float).round(precision)
   decimal.DivisionByZero: [<class 'decimal.DivisionByZero'>]
   ```
   
   Expected: percentage/ratio comparison of Decimal input follows the 
operation's existing float zero-baseline behavior, without changing 
absolute-difference precision or deciding new infinity/null rendering semantics.
   
   ### Screenshots/recordings
   
   Not applicable; backend post-processing reproduction.
   
   ### Superset version
   
   master / latest-dev
   
   ### Python version
   
   3.12.14; pandas 2.3.3 from requirements/base.txt; Windows
   
   ### Node version
   
   Not applicable
   
   ### Browser
   
   Not applicable
   
   ### Additional context
   
   Reproduced through the actual operation and project pytest tests, including 
a raw-column QueryObject passed through SqlaTable.normalize_df and 
exec_post_processing. The regression also covers plain and MultiIndex columns. 
No live database/browser/HTTP endpoint reproduction is claimed.
   
   I can prepare the focused fix and regression tests. Codex assisted with 
investigation, implementation preparation and local validation; this report 
does not represent prior human review of the code. Related Decimal contribution 
fixes concern a different operation; I found no matching Apache compare fix in 
current issue/PR searches.
   
   ### Checklist
   
   - [ ] I have searched Superset docs and Slack and didn't find a solution to 
my problem. (Public docs and GitHub searched; Slack not searched.)
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [ ] I have checked Superset's logs for errors. (Local Python/pytest 
traceback is included above; no running deployment was inspected.)
   


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