Skip to content

fix(BarChart, v1.2): treat an empty categoryColumn as no category (px.bar color) - #6997

Open
Yicong-Huang wants to merge 1 commit into
release/v1.2from
backport/6807-treat-an-empty-categorycolumn-as-no-cate-v1.2
Open

fix(BarChart, v1.2): treat an empty categoryColumn as no category (px.bar color) #6997
Yicong-Huang wants to merge 1 commit into
release/v1.2from
backport/6807-treat-an-empty-categorycolumn-as-no-cate-v1.2

Conversation

@Yicong-Huang

@Yicong-Huang Yicong-Huang commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Backport of #6807 to release/v1.2, cherry-picked from c24755c. The cherry-pick applied cleanly.

Follows the Direct Backport Push convention; opened as a PR (rather than a direct push) per a backport-coverage audit.

Any related issues, documentation, discussions?

Backport of #6807. Originally linked #6792.

How was this PR tested?

Release-branch CI runs on this PR. Cherry-pick applied cleanly onto release/v1.2; no manual conflict resolution was needed.

Was this PR authored or co-authored using generative AI tooling?

Yes — backport prepared with Claude Code (mechanical cherry-pick; the change itself is #6807 by its original author).

🤖 Generated with Claude Code

…olor) (#6807)

### What changes were proposed in this PR?

Fixes `BarChartOpDesc.generatePythonCode` treating an **unset**
`categoryColumn` as a real column, which breaks `px.bar` at runtime.

`categoryColumn`'s Scala field default is the empty string, while its
JSON `defaultValue = "No Selection"` is only schema metadata (not
applied to the Scala var, and not present when the field is absent from
the deserialized JSON). The category guard compared **only** against
`"No Selection"`:

```scala
var isCategoryColumn = "False"
if (categoryColumn != "No Selection")   // "" != "No Selection" is true
  isCategoryColumn = "True"
```

So for an empty `categoryColumn`, `isCategoryColumn` became `"True"` and
the empty column name flowed into the generated call:

```python
color=self.decode_python_template('') if True else None   # -> px.bar(color="")
```

`px.bar(color="")` raises at runtime, so a bar chart with **no category
selected** fails.

The fix also guards against empty, so an unset category yields
`color=None`:

```diff
-    if (categoryColumn != "No Selection")
+    if (categoryColumn.nonEmpty && categoryColumn != "No Selection")
```

### Any related issues, documentation, discussions?

Closes #6792

### How was this PR tested?

Added a regression test in `BarChartOpDescSpec` that constructs a
`BarChartOpDesc` with `value`/`fields` set and `categoryColumn` left at
its default, calls `generatePythonCode()`, and asserts the color site is
guarded to `None` (`... if False else None`) with no `... if True else
None`. Verified the test **fails** on the pre-fix code and **passes**
with the fix; full `BarChartOpDescSpec` is green (9/9).

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 4.8)

---------

(backported from commit c24755c)

Signed-off-by: Kary Zheng <150742834+kz930@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Yicong-Huang Yicong-Huang added the release/v1.2 back porting to release/v1.2 label Jul 29, 2026
@Yicong-Huang
Yicong-Huang requested a review from xuang7 July 29, 2026 04:11
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @aglinxinyuan
    You can notify them by mentioning @aglinxinyuan in a comment.

@Yicong-Huang Yicong-Huang removed the release/v1.2 back porting to release/v1.2 label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants