Repository navigation
Conversation
XLSX export kept raw numbers, so Table/Pivot downloads did not match the chart. Map d3 specifiers to Excel formats after the workbook is written. Co-authored-by: Cursor <cursoragent@cursor.com>
Sheet-wide color scales paint labels and blanks. Fill only numeric cells that satisfy the Explore comparator, including a value-based gradient. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…ting-export' into feature/excel-conditional-formatting-export
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| workbook_bytes, | ||
| rules, | ||
| header_rows=header_rows, | ||
| show_cell_bars=bool(form_data.get("show_cell_bars")), |
There was a problem hiding this comment.
Suggestion: When show_cell_bars is absent, the frontend defaults it to true, but this expression disables cell bars for older or minimal saved chart configurations.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Api mismatch
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/utils/excel_conditional.py
**Line:** 515:515
**Comment:**
*Api Mismatch: When `show_cell_bars` is absent, the frontend defaults it to true, but this expression disables cell bars for older or minimal saved chart configurations.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| digits = int(precision) if precision is not None else (0 if ntype in {"d", "i"} else 2) | ||
| decimals = "" if digits == 0 else "." + ("0" * digits) | ||
| grouped = "#,##0" if comma else "0" | ||
| body = f"{grouped}{decimals}" |
There was a problem hiding this comment.
Suggestion: Valid d3 n and r formats are treated as fixed decimal formats, changing grouping and significant-digit display in exported Excel files.
Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Type error
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/utils/excel_display.py
**Line:** 105:108
**Comment:**
*Type Error: Valid d3 `n` and `r` formats are treated as fixed decimal formats, changing grouping and significant-digit display in exported Excel files.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| code = str(currency.get("symbol") or "") | ||
| if not code or code == "AUTO": | ||
| return number_body |
There was a problem hiding this comment.
Suggestion: AUTO currency is discarded instead of being resolved from detected datasource currency, so configured currency columns lose their symbols in Excel exports.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Api mismatch
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/utils/excel_display.py
**Line:** 139:141
**Comment:**
*Api Mismatch: `AUTO` currency is discarded instead of being resolved from detected datasource currency, so configured currency columns lose their symbols in Excel exports.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| for metric, fmt in column_formats.items(): | ||
| if metric and (text == metric or text.endswith(metric) or text.startswith(metric)): | ||
| d3 = fmt | ||
| break |
There was a problem hiding this comment.
Suggestion: Prefix and suffix matching can select a shorter metric before the actual metric, applying the wrong number format when metric names overlap.
Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Logic error
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/utils/excel_display.py
**Line:** 233:236
**Comment:**
*Logic Error: Prefix and suffix matching can select a shorter metric before the actual metric, applying the wrong number format when metric names overlap.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
Code Review Agent Run #a9554d
Actionable Suggestions - 8
-
superset/utils/excel_display.py - 3
- Non-public openpyxl import path · Line 34-34
- d3 type n loses grouping · Line 102-103
- Duplicate workbook round-trip · Line 313-315
-
superset/utils/excel_conditional.py - 5
- Unguarded int conversion crash · Line 113-114
- Duplicate column alias logic · Line 207-207
- Unvalidated operator dict lookup · Line 361-372
- Cell bars dropped with rules · Line 460-461
- Double workbook round-trip · Line 491-517
Additional Suggestions - 18
-
superset/utils/excel_conditional.py - 11
-
Absent show_cell_bars defaults off · Line 515-515`bool(form_data.get("show_cell_bars"))` treats an absent key as False, but the Table control defaults to true (`controlPanel.tsx` `default: true`; `TableChart.tsx` `showCellBars = true`). Exports of charts whose saved form_data predates the control silently lose bars. Consider defaulting to True for `viz_type == "table"` to match the chart.
-
NaN passes numeric coercion · Line 140-140`float()` accepts "nan"/"NaN" strings and float('nan') values, so `_as_number` returns NaN. NaN comparisons are all False, so a NaN `targetValue` makes a rule silently never match, and a NaN cell value with no operator still returns True at line 152 (bar applied). Filter NaN in `_as_number`.
-
Non-numeric values silently unmatched · Line 146-146`_value_matches_rule` rejects only None/"" at line 148, but `_as_number` (line 133) accepts only int/float/str: datetime, Decimal, and boolean cell values always fail coercion, so range/comparator CELL_BAR rules silently paint nothing on date or decimal columns. If numeric-only matching is intended, document it; otherwise coerce more types.
-
Duplicated rule styling logic · Line 259-281The fill/font selection block is duplicated verbatim between `_add_formula_rule` and `_add_cell_is_rule`, and `_add_data_bar` builds its fill inline (`color=rgb`) instead of via `_solid_fill`. Three copies of the same styling logic will silently diverge when a style attribute changes. Extract a shared `_rule_fill_font(rgb, text_color)` helper and route all three rule builders through it.
-
Missing docstring on _rule_color · Line 129-130`_rule_color` is the only one of the four new helpers in this hunk without a docstring (`_hex_rgb`, `_value_matches_rule`, `_excel_literal` all have one). Per repo rule 12147, every new Python function needs an inline docstring; add a one-liner describing the fallback to `_DEFAULT_RULE_COLOR`.
-
Per-cell repeated operator lookup · Line 158-158`_matching_cell_range` (line 316) calls `_value_matches_rule` per data row, and each call re-executes `_CELL_IS_OPERATORS[operator]` at line 158 plus the six-way if-chain — O(rows) repeated dict lookups and comparisons for one invariant rule. Hoist the resolved `compare` value out of the per-cell path.
-
Redundant bool re-check · Line 188-188The `not isinstance(value, bool)` guard at line 188 is dead: every bool already returned at line 187 (`isinstance(value, bool)` is checked first). The condition can be plain `isinstance(value, (int, float))` without changing behavior.
-
Duplicated operator sentinel · Line 306-306This repeats the no-operator sentinel `(None, "None", "")` already tested in `_value_matches_rule` (line 151). The two checks must stay in sync: if one gains a new sentinel, the range builder and the per-cell predicate will disagree on which rules are unconditional. Consider a shared module constant used by both.
-
Loop-invariant rule reparse · Line 316-316`_value_matches_rule` re-reads `rule["operator"]` and re-parses `targetValue` / `targetValueLeft` / `targetValueRight` via `_as_number` on every call, and line 316 invokes it once per data row. On report-sized exports the same invariants are parsed N times; hoisting the parsed comparator above the loop keeps the scan O(n) without the repeated parsing.
-
None target stringifies to None · Line 171-171For numeric-only operators, when `targetValue` is absent (`target` is None) the fallback at line 171 compares `str(value) == "None"` — a cell containing the literal text 'None' would match a `>` rule. Guard the fallback with `target is not None` so a missing target never matches.
-
Tuple membership TypeError risk · Line 134-134`value in (None, "")` evaluates `value == None` then `value == ""`; for array-like cell values that can survive into openpyxl (numpy scalars/arrays from pandas frames) this raises Python's 'truth value of an array is ambiguous' `TypeError` instead of returning False. Same pattern at line 148. Safer: `value is None or (isinstance(value, str) and not value)`.
-
-
tests/unit_tests/utils/test_excel_display.py - 2
-
Missing test docstrings · Line 35-158This new file adds 8 test functions (`test_d3_number_to_excel_common_specifiers`, `test_d3_time_to_excel_common_patterns`, `test_styles_from_table_form_data_generated_config`, `test_styles_from_table_form_data_resolves_verbose_headers`, `test_styles_from_pivot_form_data_matches_flattened_metric`, `test_apply_column_display_on_generated_workbook`, `test_apply_column_display_formats_datetimes`, `test_apply_column_display_xlsxwriter_roundtrip_alignment`) but none carry a docstring. Per the repo's adaptive rule, every newly added test function must document its purpose and expected behavior.
-
Missing local type hints · Line 105-158Local variables in the new tests (e.g. `workbook`, `sheet`, `raw`, `styled`, `frame`, `result`, `cell` at lines 105-158) carry no type annotations. The repo's adaptive rule requires explicit type annotations on all local variables in test files, even when inferable.
-
-
superset/utils/excel_display.py - 5
-
Magic regex group indices · Line 100-100Bare indices 7/8/10 index the 10-group `D3_FORMAT_RE` defined on line 39; nothing at the unpacking site says which flag each group is, so a grammar edit upstream silently misbinds these. A one-line comment naming the captured groups (`,` flag, `.precision`, type) prevents that drift.
-
Hardcoded AUTO currency sentinel · Line 140-140`"AUTO"` duplicates the `AUTO_CURRENCY` sentinel defined in `superset/utils/number_format.py:49`; if that constant ever changes, this check silently diverges and AUTO currencies would be quoted as literal symbols. Import and reuse `AUTO_CURRENCY` instead of the hardcoded literal.
-
Currency symbol unescaped in numFmt · Line 142-143`_currency_excel_format` embeds `symbol` verbatim inside Excel double quotes; a symbol containing `"` would corrupt the numFmt. Current producers are safe — the currency control sends ISO codes (`transformProps.ts:262`) and `_CURRENCY_EXCEL_SYMBOL` values contain no quotes — so this is future-proofing: consider doubling embedded quotes.
-
%I maps to 24-hour Excel hh · Line 54-54`%I` is the 12-hour strftime token, but Excel's `hh` code displays hours 0-23 unless `AM/PM` follows. For a user format like `%I:%M` (no `%p`), `d3_time_to_excel` yields `hh:mm` and cells show 13:05 for 1:05 PM. Dropping the entry makes such formats return None so the cell keeps the writer's default datetime format rather than displaying a wrong hour.
-
Missing docstring on helper · Line 257-257`_stamp_column_style` is the only new function in this module without a docstring; BITO rule 12147 requires docstrings on all new Python functions, including helpers. Adding one documents the `header_row + 1` data-cell range contract that `apply_column_display` relies on.
-
Filtered by Review Rules
Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
-
superset/utils/excel_display.py - 2
- Duplicated d3 grammar and constants · Line 37-43
- Currency symbol map duplicates babel · Line 62-71
Review Details
-
Files reviewed - 8 · Commit Range:
467c610..8f3750d- superset/charts/client_processing.py
- superset/common/query_context_processor.py
- superset/utils/excel_conditional.py
- superset/utils/excel_display.py
- tests/unit_tests/charts/test_client_processing.py
- tests/unit_tests/common/test_query_context_processor.py
- tests/unit_tests/utils/test_excel_conditional.py
- tests/unit_tests/utils/test_excel_display.py
-
Files skipped - 0
-
Tools
- MyPy (Static Code Analysis) - ✔︎ Successful
- Astral Ruff (Static Code Analysis) - ✔︎ Successful
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- Manually triggers an incremental AI Review. -
/review full- Manually triggers a full AI Review. -
/pause- Pauses automatic reviews on this pull request. -
/resume- Resumes automatic reviews. -
/resolve- Marks all Bito-posted review comments as resolved. -
/abort- Cancels all in-progress reviews.
Refer to the documentation for additional commands.
Configuration
This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.
Documentation & Help
| from datetime import date, datetime | ||
| from typing import Any, Mapping | ||
|
|
||
| from openpyxl.reader.excel import load_workbook |
There was a problem hiding this comment.
This imports load_workbook from the internal openpyxl.reader.excel module. The public entry point is openpyxl.load_workbook, which is what sibling superset/utils/excel_conditional.py (line 35) uses in this same feature. The internal path is functionally identical on the pinned openpyxl 3.1.5, but it is not covered by openpyxl's public API contract and diverges from the sibling module's import style.
Code Review Run #a9554d
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| if ntype in {"s", "e"}: | ||
| return None |
There was a problem hiding this comment.
d3_number_to_excel silently drops the n (grouped thousands) type that the repo's own format_d3 supports (superset/utils/number_format.py:258 maps n to comma-grouped output): an n-type specifier falls through to the default body without #,##0 grouping, so exported cells lose the thousands separators the chart shows. Force grouping for n before building body.
Code suggestion
Check the AI-generated fix before applying
| if ntype in {"s", "e"}: | |
| return None | |
| if ntype in {"s", "e"}: | |
| return None | |
| if ntype == "n": | |
| comma = "," |
Code Review Run #a9554d
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| output = io.BytesIO() | ||
| workbook.save(output) | ||
| return output.getvalue() |
There was a problem hiding this comment.
apply_column_display loads the workbook (line 286) and re-saves it (lines 313-315). In polish_explore_xlsx it runs before apply_conditional_formatting, which repeats the identical load/save, so styled exports with CF rules parse and serialize the whole workbook twice. Consider sharing one loaded Workbook across both passes.
Code Review Run #a9554d
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| if None not in (red, green, blue): | ||
| return f"{int(red):02X}{int(green):02X}{int(blue):02X}" |
There was a problem hiding this comment.
_hex_rgb guards missing r/g/b keys but not non-numeric values: int(red) on colorScheme={"r": "0xFF", ...} raises ValueError (on None-typed values, TypeError). colorScheme comes from user-controlled form_data JSON, so this aborts the whole XLSX download in polish_explore_xlsx. Catch the conversion failure and return None to fall back to _DEFAULT_RULE_COLOR.
Code Review Run #a9554d
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| column: str, verbose_map: Optional[Mapping[str, Any]] | ||
| ) -> list[str]: | ||
| """Raw and verbose names so rules still match after datasource rename.""" | ||
| aliases = [column] |
There was a problem hiding this comment.
The alias resolution logic is duplicated in superset/utils/excel_conditional.py (lines 207-219) and superset/utils/excel_display.py (lines 153-165). Consider moving it to a common utility to avoid divergence.
Code Review Run #a9554d
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| if operator in _CELL_IS_OPERATORS: | ||
| _add_cell_is_rule( | ||
| sheet, | ||
| cell_range, | ||
| _CELL_IS_OPERATORS[operator], | ||
| [_excel_literal(rule.get("targetValue"))], | ||
| rgb, | ||
| text_color=text_color, | ||
| ) | ||
| return | ||
|
|
||
| if operator in _RANGE_OPERATORS: |
There was a problem hiding this comment.
operator = rule.get("operator") is used unvalidated in operator in _CELL_IS_OPERATORS (line 361) and operator in _RANGE_OPERATORS (line 372). Rules come from user-controlled chart form_data (conditionalFormatting) via polish_explore_xlsx; a rule with a non-string, unhashable operator (e.g. a list or dict, which JSON allows) raises TypeError: unhashable type and aborts the XLSX download. column is type-checked at line 340 but operator is not. Coerce non-string operators to None after line 350.
Code Review Run #a9554d
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| if show_cell_bars and not rules: | ||
| _apply_cell_bars(sheet, header_row) |
There was a problem hiding this comment.
The Table chart renders showCellBars (control default true, controlPanel.tsx) independently of conditional formatting, but apply_conditional_formatting adds default data bars only when not rules. A download with any CF rule and bars enabled loses all cell bars, diverging from the chart. If fallback-only is intended, consider documenting why; otherwise apply _apply_cell_bars whenever show_cell_bars is set.
Code Review Run #a9554d
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
| workbook_bytes = apply_column_display( | ||
| workbook_bytes, | ||
| styles, | ||
| header_rows=header_rows, | ||
| ordered_headers=headers, | ||
| index_columns=( | ||
| int(getattr(df.index, "nlevels", 1)) if include_index else 0 | ||
| ), | ||
| ) | ||
| else: | ||
| styles = styles_from_pivot_form_data(headers, form_data) | ||
| workbook_bytes = apply_column_display( | ||
| workbook_bytes, styles, header_rows=header_rows | ||
| ) | ||
|
|
||
| rules = form_data.get("conditionalFormatting") or form_data.get( | ||
| "conditional_formatting" | ||
| ) | ||
| if not isinstance(rules, list): | ||
| rules = [] | ||
| return apply_conditional_formatting( | ||
| workbook_bytes, | ||
| rules, | ||
| header_rows=header_rows, | ||
| show_cell_bars=bool(form_data.get("show_cell_bars")), | ||
| verbose_map=verbose_map, | ||
| ) |
There was a problem hiding this comment.
polish_explore_xlsx round-trips the workbook twice when display styles and rules/bars both apply: apply_column_display loads and re-saves the bytes, then apply_conditional_formatting (line 511) loads and saves again. For large exports this doubles openpyxl serialization cost; consider sharing one loaded Workbook via an internal helper.
Code Review Run #a9554d
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #44719 +/- ##
==========================================
- Coverage 81.13% 81.10% -0.04%
==========================================
Files 2956 2958 +2
Lines 178453 178889 +436
Branches 41345 41454 +109
==========================================
+ Hits 144784 145081 +297
- Misses 30965 31048 +83
- Partials 2704 2760 +56
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks @bazhil! Closing this one since it's stacked on #44664, which you're still actively working on, and that PR already matches |
|
Ok, cool! Happy to reopen this and put it on draft mode if you'd like. |
|
@rusackas Yes, i would like to reopen draft for further fixes, when time is come. |
SUMMARY
Table Explore already honors per-column Text align (
column_config.horizontalAlign)in the chart. XLSX download wrote number/date formats through
polish_explore_xlsx,but alignment was dropped when
column_configkeys did not match the sheet headers(after
verbose_maprename) or when styles were matched only by reading headercells from an xlsxwriter workbook.
This change resolves
column_configkeys against raw and verbose names (same ideaas native Excel CF on this stack) and stamps
Alignmentonto data cells bycolumn index for Table exports, so left/center/right from Customize show up in
Excel for both numeric and string columns.
No UI, API, or migration changes. Pivot display path is unchanged (no Table-style
horizontalAlignthere).BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before (
feature/excel-conditional-formatting-exportwithout this patch):Explore Table, Customize → Text align center on
qty,sample_flag,salesperson. Chart cells are centered. Downloaded XLSX keeps defaultleft/General alignment on those columns.
After (this branch): the same columns in the XLSX are centered (LibreOffice /
Excel cell alignment). Chart unchanged.
TESTING INSTRUCTIONS
feature/excel-table-text-align(includes Excel polish from feat(excel): export Explore conditional formatting as native Excel rules #44664).and a string column. Confirm the on-screen table updates.
Alignment, or visual check on a wide column).
column_name— configstill keyed by the physical name; the sheet header is the label. Alignment
should still apply.
pytest tests/unit_tests/utils/test_excel_display.py \ tests/unit_tests/utils/test_excel_conditional.py -qADDITIONAL INFORMATION