mistercrunch opened a new pull request, #37869:
URL: https://github.com/apache/superset/pull/37869
## Summary
Fixes #12066 — a 5-year-old bug where using multiple "Group By" columns in a
**Time-Series Table** chart causes:
```
TypeError: keys must be str, int, float, bool or None, not tuple
```
### Root Cause
When multiple `groupby` columns are specified, `df.pivot_table()` produces a
`pd.MultiIndex` on columns (tuples like `("category_a", "region_1")`). Calling
`pt.to_dict(orient="index")` then fails because JSON cannot serialize tuple
keys.
### Fix
After `pivot_table()` and sorting, flatten any `MultiIndex` columns to
comma-separated strings before serialization:
```python
if isinstance(pt.columns, pd.MultiIndex):
pt.columns = [", ".join(str(s) for s in col) for col in pt.columns]
```
This is a **2-line change** in `superset/viz.py`
(`TimeTableViz.get_data()`). The fix is compatible with the frontend, which
already expects string column keys.
### Test Plan
- [x] Added `test_get_data_multiple_group_by` integration test that
exercises the multiple-groupby path and asserts flattened string keys in both
`records` and `columns`
- [x] Existing `TestTimeSeriesTableViz` tests continue to pass (single
groupby and no-groupby paths unchanged)
### Confirmed Affected Versions
Reported across 0.26, 0.35, 1.1, 1.3, 1.4, 2.0.1, 2.1.3, 3.0.1, 4.0.1, and
4.1.1.
--
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]