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

   ### Bug description
   
   When creating heatmaps (both tested in 6.0.0 and 6.1.0) with normalisation 
across X/Y (and posibly color normalisation), the plot will fail when only one 
column/row is left by applying dynamic filters.
   
   Example is in the flights sample dataset, on a fresh install, putting 
`AIRLINE` as the X and `CITY` as Y (metric `COUNT(*)` or `SUM(AIRLINE_DELAY)` 
or anything else).
   
   <img width="1492" height="818" alt="Image" 
src="https://github.com/user-attachments/assets/411bc601-0ec8-4b98-ba63-d8ac208f7936";
 />
   
   It works as expected with the normalisation across X (above), but as soon as 
a filter reducing the data to a single column (like `AIRLINE = 'AA'`), a 
"Cannot set a DataFrame with multiple columns to the single column rank" error 
is shown.
   
   <img width="1492" height="818" alt="Image" 
src="https://github.com/user-attachments/assets/95804232-048f-421d-81df-8b862cf994f7";
 />
   
   The weird thing is that then the plot works with no issues if one normalises 
across rows (Y) (the same works when normalising across platform):
   
   <img width="1492" height="818" alt="Image" 
src="https://github.com/user-attachments/assets/a5d7e808-cc76-455e-9b2e-2b1d18f0782d";
 />
   
   To conclude, an unexptected behavior is also found when reducing both the 
rows and the columns to 1:
   
   - If one normalises across X/Y we get an empty plot (should plot a single 
square with 100% in both cases)
   
   <img width="1486" height="858" alt="Image" 
src="https://github.com/user-attachments/assets/4fc90c92-8266-4fa5-9093-d32b282460ed";
 />
    
   - Instead, when normalising over the heatmap this is working as expected:
   
   <img width="1496" height="847" alt="Image" 
src="https://github.com/user-attachments/assets/8b1604e6-43c9-4161-9cd6-0a1401eeb1bd";
 />
   
   This might be related to the underlying eChart heatmap implementation (and 
the error thrown [stems from 
pandas](https://stackoverflow.com/questions/75500734/cannot-set-a-dataframe-with-multiple-columns-to-the-single-column-total-servings)
 postprocessing rank function) but I am struggling to understand where to look 
in the codebase to check for issues.
   
   Let me know should you need any additional information, thanks!
   
   ### Screenshots/recordings
   
   Example is in the flights sample dataset, on a fresh install, putting 
`AIRLINE` as the X and `CITY` as Y (metric `COUNT(*)` or `SUM(AIRLINE_DELAY)` 
or anything else).
   
   <img width="1492" height="818" alt="Image" 
src="https://github.com/user-attachments/assets/411bc601-0ec8-4b98-ba63-d8ac208f7936";
 />
   
   It works as expected with the normalisation across X (above), but as soon as 
a filter reducing the data to a single column (like `AIRLINE = 'AA'`), a 
"Cannot set a DataFrame with multiple columns to the single column rank" error 
is shown.
   
   <img width="1492" height="818" alt="Image" 
src="https://github.com/user-attachments/assets/95804232-048f-421d-81df-8b862cf994f7";
 />
   
   The weird thing is that then the plot works with no issues if one normalises 
across rows (Y) (the same works when normalising across platform):
   
   <img width="1492" height="818" alt="Image" 
src="https://github.com/user-attachments/assets/a5d7e808-cc76-455e-9b2e-2b1d18f0782d";
 />
   
   To conclude, an unexptected behavior is also found when reducing both the 
rows and the columns to 1:
   
   - If one normalises across X/Y we get an empty plot (should plot a single 
square with 100% in both cases)
   
   <img width="1486" height="858" alt="Image" 
src="https://github.com/user-attachments/assets/4fc90c92-8266-4fa5-9093-d32b282460ed";
 />
    
   - Instead, when normalising over the heatmap this is working as expected:
   
   <img width="1496" height="847" alt="Image" 
src="https://github.com/user-attachments/assets/8b1604e6-43c9-4161-9cd6-0a1401eeb1bd";
 />
   
   
   
   ### Superset version
   
   6.0.0
   
   ### Python version
   
   3.10
   
   ### Node version
   
   18 or greater
   
   ### Browser
   
   Not applicable
   
   ### Additional context
   
   Here is the python stacktrace from container logs:
   
   ```
   2026-06-03 12:27:08,053:WARNING:superset.views.error_handling:Exception
   Traceback (most recent call last):
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/flask/app.py",
 line 917, in full_dispatch_request
       rv = self.dispatch_request()
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/flask/app.py",
 line 902, in dispatch_request
       return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) 
 # type: ignore[no-any-return]
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/flask_appbuilder/security/decorators.py",
 line 101, in wraps
       return f(self, *args, **kwargs)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/views/base_api.py",
 line 120, in wraps
       duration, response = time_function(f, self, *args, **kwargs)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/utils/core.py",
 line 1559, in time_function
       response = func(*args, **kwargs)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/utils/log.py",
 line 299, in wrapper
       value = f(*args, add_extra_log_payload=log, **kwargs)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/charts/data/api.py",
 line 289, in data
       return self._get_data_response(
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/utils/log.py",
 line 301, in wrapper
       value = f(*args, **kwargs)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/charts/data/api.py",
 line 496, in _get_data_response
       result = command.run(force_cached=force_cached)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/commands/chart/data/get_data_command.py",
 line 46, in run
       payload = self._query_context.get_payload(
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context.py",
 line 99, in get_payload
       return self._processor.get_payload(cache_query_context, force_cached)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context_processor.py",
 line 353, in get_payload
       query_results = [
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context_processor.py",
 line 354, in <listcomp>
       get_query_results(
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_actions.py",
 line 290, in get_query_results
       return result_func(query_context, query_obj, force_cached)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_actions.py",
 line 160, in _get_full
       payload = query_context.get_df_payload(query_obj, 
force_cached=force_cached)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context.py",
 line 129, in get_df_payload
       return self._processor.get_df_payload(
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context_processor.py",
 line 131, in get_df_payload
       query_result = self.get_query_result(query_obj)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context_processor.py",
 line 243, in get_query_result
       return self._qc_datasource.get_query_result(query_object)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/models/helpers.py",
 line 1343, in get_query_result
       df = query_object.exec_post_processing(df)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_object.py",
 line 542, in exec_post_processing
       df = getattr(pandas_postprocessing, operation)(df, **options)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/utils/pandas_postprocessing/rank.py",
 line 37, in rank
       df["rank"] = gb.apply(lambda x: x[metric].rank(pct=True))
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/pandas/core/frame.py",
 line 4081, in __setitem__
       self._set_item_frame_value(key, value)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/pandas/core/frame.py",
 line 4239, in _set_item_frame_value
       raise ValueError(
   ValueError: Cannot set a DataFrame with multiple columns to the single 
column rank
   2026-06-03 12:27:08,053:ERROR:superset.views.error_handling:Cannot set a 
DataFrame with multiple columns to the single column rank
   Traceback (most recent call last):
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/flask/app.py",
 line 917, in full_dispatch_request
       rv = self.dispatch_request()
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/flask/app.py",
 line 902, in dispatch_request
       return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) 
 # type: ignore[no-any-return]
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/flask_appbuilder/security/decorators.py",
 line 101, in wraps
       return f(self, *args, **kwargs)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/views/base_api.py",
 line 120, in wraps
       duration, response = time_function(f, self, *args, **kwargs)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/utils/core.py",
 line 1559, in time_function
       response = func(*args, **kwargs)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/utils/log.py",
 line 299, in wrapper
       value = f(*args, add_extra_log_payload=log, **kwargs)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/charts/data/api.py",
 line 289, in data
       return self._get_data_response(
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/utils/log.py",
 line 301, in wrapper
       value = f(*args, **kwargs)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/charts/data/api.py",
 line 496, in _get_data_response
       result = command.run(force_cached=force_cached)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/commands/chart/data/get_data_command.py",
 line 46, in run
       payload = self._query_context.get_payload(
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context.py",
 line 99, in get_payload
       return self._processor.get_payload(cache_query_context, force_cached)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context_processor.py",
 line 353, in get_payload
       query_results = [
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context_processor.py",
 line 354, in <listcomp>
       get_query_results(
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_actions.py",
 line 290, in get_query_results
       return result_func(query_context, query_obj, force_cached)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_actions.py",
 line 160, in _get_full
       payload = query_context.get_df_payload(query_obj, 
force_cached=force_cached)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context.py",
 line 129, in get_df_payload
       return self._processor.get_df_payload(
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context_processor.py",
 line 131, in get_df_payload
       query_result = self.get_query_result(query_obj)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_context_processor.py",
 line 243, in get_query_result
       return self._qc_datasource.get_query_result(query_object)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/models/helpers.py",
 line 1343, in get_query_result
       df = query_object.exec_post_processing(df)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/common/query_object.py",
 line 542, in exec_post_processing
       df = getattr(pandas_postprocessing, operation)(df, **options)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/superset/utils/pandas_postprocessing/rank.py",
 line 37, in rank
       df["rank"] = gb.apply(lambda x: x[metric].rank(pct=True))
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/pandas/core/frame.py",
 line 4081, in __setitem__
       self._set_item_frame_value(key, value)
     File 
"/home/user/.local/share/pipx/venvs/apache-superset/lib/python3.10/site-packages/pandas/core/frame.py",
 line 4239, in _set_item_frame_value
       raise ValueError(
   ValueError: Cannot set a DataFrame with multiple columns to the single 
column rank
   ```
   
   ### Checklist
   
   - [x] 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