You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "EUbaldiEC (via GitHub)" <gi...@apache.org> on 2026/06/03 12:33:32 UTC
[I] Heatmap with "Normalize Across" x/y will fail when filters reduce the data to a single column/row. [superset]
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: notifications-unsubscribe@superset.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Heatmap with "Normalize Across" x/y will fail when filters reduce the data to a single column/row. [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas closed issue #40709: Heatmap with "Normalize Across" x/y will fail when filters reduce the data to a single column/row.
URL: https://github.com/apache/superset/issues/40709
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Heatmap with "Normalize Across" x/y will fail when filters reduce the data to a single column/row. [superset]
Posted by "EUbaldiEC (via GitHub)" <gi...@apache.org>.
EUbaldiEC commented on issue #40709:
URL: https://github.com/apache/superset/issues/40709#issuecomment-4617236735
Hi,
The bot pointed me in the (almost) right direction.
Turns out the second line in the if block within [rank.py](https://github.com/apache/superset/blob/master/superset/utils/pandas_postprocessing/rank.py#L35)
```python
if group_by:
gb = df.groupby(group_by, group_keys=False)
df["rank"] = gb.apply(lambda x: x[metric].rank(pct=True))
```
will fail when the heatmap has only one row/column.
Substituting it with:
```python
if group_by:
df["rank"] = df.groupby(group_by)[metric].rank(pct=True)
```
solves the issue.
Running the old version against the test categories df, but filtered for one category, does indeed raise the error:
```python
> tmp_df = categories_df[categories_df["dept"]=="dept0"].reset_index(drop=True)
> tmp_df.drop(columns=["rank"], errors="ignore", inplace=True)
> rank_upstream(tmp_df, "asc_idx", "dept") # Prev version
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
....
ValueError: Cannot set a DataFrame with multiple columns to the single column rank
> tmp_df = categories_df[categories_df["dept"]=="dept0"].reset_index(drop=True)
> tmp_df.drop(columns=["rank"], errors="ignore", inplace=True)
> rank(tmp_df, "asc_idx", "dept") # NEW version
constant category dept name asc_idx desc_idx idx_nulls rank
0 dummy cat0 dept0 person0 0 100 0.0 0.047619
1 dummy cat2 dept0 person5 5 95 5.0 0.095238
2 dummy cat1 dept0 person10 10 90 10.0 0.142857
...
```
I am drafting a PR with all the details and unit tests, but can already show here that this is working as expected in the failing scenarios (while preserving the same behaviour in the ones already functioning).
- Overall case (same works with normalisation across heatmap / y):
<img width="1489" height="838" alt="Image" src="https://github.com/user-attachments/assets/7fb21b04-afab-44f3-9d0d-bb77916f666b" />
- Single column and normalize across X:
<img width="1485" height="840" alt="Image" src="https://github.com/user-attachments/assets/a46e19fd-d2c5-4604-a96b-3e72a388f367" />
- Single row and normalize across Y:
<img width="1493" height="841" alt="Image" src="https://github.com/user-attachments/assets/6a86e433-40a9-478f-b978-b8c6f187c1da" />
- Single row AND column:
<img width="1519" height="839" alt="Image" src="https://github.com/user-attachments/assets/ad808981-2fa0-4970-af25-544cd51b8572" />
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Heatmap with "Normalize Across" x/y will fail when filters reduce the data to a single column/row. [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #40709:
URL: https://github.com/apache/superset/issues/40709#issuecomment-4612360696
<!-- Answer -->
Thanks for the detailed report! I can confirm this is a bug in the pandas postprocessing `rank` function.
The issue is in [`superset/utils/pandas_postprocessing/rank.py` at line 37](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/utils/pandas_postprocessing/rank.py#L35-L37):
```python
if group_by:
gb = df.groupby(group_by, group_keys=False)
df["rank"] = gb.apply(lambda x: x[metric].rank(pct=True))
```
When "Normalize Across X" is selected and a filter reduces the data to a single X value (single column), the `groupby` on that column produces groups where each group has only one row. In newer versions of pandas, `gb.apply(lambda x: x[metric].rank(pct=True))` can return a DataFrame with multiple columns instead of a Series when each group has a single element, causing the `ValueError: Cannot set a DataFrame with multiple columns to the single column rank` error.
This is a known pandas behavior change — when `apply` is called on single-element groups, pandas may not properly infer the return type and returns a DataFrame instead of a Series.
**A potential fix** would be to ensure the result is always a Series before assignment, for example:
```python
if group_by:
gb = df.groupby(group_by, group_keys=False)
result = gb.apply(lambda x: x[metric].rank(pct=True))
if isinstance(result, pd.DataFrame):
result = result.iloc[:, 0]
df["rank"] = result
else:
df["rank"] = df[metric].rank(pct=True)
```
Or alternatively, using `transform` instead of `apply` which always returns a Series aligned with the original DataFrame:
```python
if group_by:
gb = df.groupby(group_by, group_keys=False)
df["rank"] = gb[metric].transform(lambda x: x.rank(pct=True))
```
The `transform` approach is likely cleaner since it avoids the `apply` return-type ambiguity altogether and is semantically more appropriate here (we want a value per row, not an aggregation).
For the secondary issue (empty plot when both X and Y are reduced to a single value with normalize across X/Y), that's likely because a single-element group produces a rank of `NaN` or `1.0` that may not map correctly to the visualization — but fixing the `ValueError` above should make that case reachable for further debugging.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=ad960abe-149e-4b02-a989-816cbb1510b2) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Heatmap with "Normalize Across" x/y will fail when filters reduce the data to a single column/row. [superset]
Posted by "Mady356 (via GitHub)" <gi...@apache.org>.
Mady356 commented on issue #40709:
URL: https://github.com/apache/superset/issues/40709#issuecomment-4789109220
Hi, I was exploring the repo and would love to work on this issue if possible?
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Heatmap with "Normalize Across" x/y will fail when filters reduce the data to a single column/row. [superset]
Posted by "Raman-Katiyar (via GitHub)" <gi...@apache.org>.
Raman-Katiyar commented on issue #40709:
URL: https://github.com/apache/superset/issues/40709#issuecomment-4651552757
Hi! I'd like to work on this issue.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org