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

   ### Bug description
   
   The `rank` post-processing operation ignores `group_by=""`, even when the 
DataFrame has a column with that name. It computes a global percentile rank 
instead of ranking within each group.
   
   An empty string is a valid pandas column label. `group_by` is typed as `str 
| None`, and `None` already represents an unspecified grouping column. The 
truthiness check in `superset/utils/pandas_postprocessing/rank.py` treats both 
values alike.
   
   ### How to reproduce the bug
   
   Run this in a Superset development environment:
   
   ```python
   import pandas as pd
   from superset.utils import pandas_postprocessing as pp
   
   df = pd.DataFrame({"": ["A", "A", "B", "B"], "value": [1, 3, 2, 4]})
   
   print(pp.rank(df.copy(), "value", group_by="")["rank"].tolist())
   # Actual: [0.25, 0.75, 0.5, 1.0]
   
   print(df.groupby("")["value"].rank(pct=True).tolist())
   # Expected: [0.5, 1.0, 0.5, 1.0]
   ```
   
   The same group values under a non-empty column name produce the expected 
group-wise ranks. Omitting `group_by` or passing `None` should continue to 
compute global ranks.
   
   ### Screenshots/recordings
   
   Not applicable: this reproduction exercises a backend DataFrame operation.
   
   ### Superset version
   
   master / latest-dev, commit `42bbfa49079eff910ead01b7880b94d09c5ca520`
   
   ### Python version
   
   3.12.14
   
   ### Node version
   
   Not applicable
   
   ### Browser
   
   Not applicable
   
   ### Additional context
   
   Verified with pandas 2.3.3 in the project's pytest environment. The minimal 
fix is to check `group_by is not None` rather than its truthiness. A regression 
test covers an empty-string column label, an ordinary label, and explicit 
`None`; existing tests cover omitted grouping and a single group.
   
   I have prepared a fix and tests for this issue.
   
   ### Checklist
   
   - [ ] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [x] I have checked Superset's logs for errors and if I found a relevant 
Python stacktrace, I included it here as text in the "additional context" 
section.
   


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