Skip to content

Fix bar chart error with uniform column values#13590

Merged
kmcgrady merged 1 commit intodevelopfrom
kmcgrady/bar-chart-uniform-fix
Jan 14, 2026
Merged

Fix bar chart error with uniform column values#13590
kmcgrady merged 1 commit intodevelopfrom
kmcgrady/bar-chart-uniform-fix

Conversation

@sfc-gh-kmcgrady
Copy link
Copy Markdown
Contributor

Describe your changes

Fixed the "Invalid min/max y-axis configuration" error that occurred when rendering bar charts with uniform (identical) values in a column without explicit y_min/y_max bounds. The fix changes the condition from checking single-element arrays to checking if all values are identical (minValue === maxValue), applying the same bounds logic to both cases.

GitHub Issue Link

Fixes #13584

Testing Plan

  • Added comprehensive unit tests covering uniform positive values, zero values, and negative values
  • All 28 existing and new tests pass
  • Verified linting passes on modified files

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

Handle multi-element arrays where all values are identical by checking minValue === maxValue instead of just chartData.length === 1. This allows charts with uniform values to render with appropriate y-axis bounds (e.g., [0, value] for positive uniform values) without throwing 'Invalid min/max y-axis configuration' error.

Co-Authored-By: Claude <[email protected]>
Copilot AI review requested due to automatic review settings January 14, 2026 19:36
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Jan 14, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 14, 2026

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-13590/streamlit-1.52.2-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-13590.streamlit.app (☁️ Deploy here if not accessible)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where bar charts would throw an "Invalid min/max y-axis configuration" error when all values in a column were identical (uniform) but the array contained more than one element. The fix generalizes the existing single-element logic to handle all cases where minValue === maxValue.

Changes:

  • Modified the condition from chartData.length === 1 to minValue === maxValue to handle uniform values regardless of array length
  • Added a descriptive comment explaining the purpose of the conditional block
  • Removed an outdated inline comment
  • Added comprehensive test coverage for uniform positive, zero, and negative values

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
frontend/lib/src/components/widgets/DataFrame/columns/ChartColumn.ts Changed the condition to detect uniform values by comparing min and max values instead of checking array length
frontend/lib/src/components/widgets/DataFrame/columns/ChartColumn.test.ts Added test cases for uniform values (positive, zero, negative) without explicit y_min/y_max configuration

@kmcgrady kmcgrady added ai-review If applied to PR or issue will run AI review workflow security-assessment-completed change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Jan 14, 2026
@github-actions github-actions bot removed the ai-review If applied to PR or issue will run AI review workflow label Jan 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Summary

This PR fixes a bug (#13584) where bar charts with uniform (identical) values in a DataFrame column caused an "Invalid min/max y-axis configuration" error when no explicit y_min/y_max bounds were configured. The fix changes the condition for applying special bounds logic from checking for single-element arrays (chartData.length === 1) to checking if all values are identical (minValue === maxValue).

Files changed:

  • frontend/lib/src/components/widgets/DataFrame/columns/ChartColumn.ts - 3 additions, 2 deletions
  • frontend/lib/src/components/widgets/DataFrame/columns/ChartColumn.test.ts - 23 additions

Code Quality

The code change is minimal, targeted, and well-implemented:

ChartColumn.ts (lines 207-215):

  • ✅ The condition change from chartData.length === 1 to minValue === maxValue correctly handles both single-element arrays AND multi-element arrays where all values are identical
  • ✅ The comment was appropriately updated to explain the new behavior: "Handle case where all values are identical (including single-element arrays)"
  • ✅ The old comment //maxValue = minValue (only one value in chartData) was correctly removed as it was outdated
  • ✅ The bounds logic correctly handles three edge cases:
    • Uniform positive values: y_min=0, y_max=value
    • Uniform zero values: y_min=0, y_max=1 (to avoid min >= max error)
    • Uniform negative values: y_min=value, y_max=0

The fix is logically equivalent for single-element arrays (since a single element has minValue === maxValue by definition), ensuring backwards compatibility.

Test Coverage

Unit Tests (lines 265-286):

  • ✅ The new test case "handles uniform values without explicit y_min/y_max configuration" is comprehensive
  • ✅ Tests three scenarios: uniform positive values [4, 4, 4, 4], uniform zero values [0, 0, 0], and uniform negative values [-5, -5, -5]
  • ✅ Includes negative assertions (isErrorCell(mockCell).toEqual(false)) as recommended by the TypeScript testing guidelines
  • ✅ Verifies both the data values and the computed yAxis bounds
  • ✅ Includes a reference to the GitHub issue for traceability
  • ✅ Uses existing test patterns and helper functions (getBarChartColumn(), isErrorCell())
  • ✅ Follows the existing test structure in the file

Relationship to existing tests:

  • The existing test at line 246 ("works with single values or only same values without running into division by zero") tests uniform values WITH explicit y_min/y_max configuration
  • The new test complements this by testing uniform values WITHOUT explicit configuration - this is exactly where the bug occurred

E2E Coverage:

  • E2E tests exist for bar chart columns in st_dataframe_config_test.py with screenshot comparisons
  • The existing E2E coverage is adequate for this fix since:
    • The bug manifested as an error cell, not a visual regression
    • The unit tests thoroughly verify the fix
    • Visual appearance of working uniform-value charts is unchanged

Backwards Compatibility

Fully backwards compatible:

  • Single-element array behavior is preserved (they also satisfy minValue === maxValue)
  • The change only makes previously failing cases work - it doesn't change any working behavior
  • No API changes or breaking changes for users
  • Existing tests continue to pass

Security & Risk

No security concerns identified:

  • The change is purely computational logic for chart rendering
  • No user input handling changes
  • No data exposure risks

Low regression risk:

  • The fix is minimal (3 lines changed)
  • The existing test at line 246 ("works with single values...") continues to verify the division-by-zero protection with explicit bounds
  • The new condition is a strict superset of the old condition
  • All 28 existing and new tests pass (as stated in PR description)

Recommendations

No changes requested. The PR is well-implemented:

  1. ✅ The fix correctly addresses the root cause
  2. ✅ Test coverage is comprehensive with positive and negative assertions
  3. ✅ The code follows existing patterns and conventions
  4. ✅ The change is minimal and focused
  5. ✅ Comment was appropriately updated

Minor observation (informational only):

  • The test uses getBarChartColumn() specifically, but the fix applies to all chart types (LineChartColumn, BarChartColumn, AreaChartColumn) since they all use BaseChartColumn. This is acceptable since the underlying logic is shared.

Verdict

APPROVED: This is a well-implemented bug fix with comprehensive test coverage, minimal code changes, and no backwards compatibility concerns. The fix correctly generalizes the condition to handle all uniform-value arrays, not just single-element arrays.


This is an automated AI review. Please verify the feedback and use your judgment.

@kmcgrady kmcgrady merged commit 9a1d51c into develop Jan 14, 2026
83 of 85 checks passed
@kmcgrady kmcgrady deleted the kmcgrady/bar-chart-uniform-fix branch January 14, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bar Chart Fails with 'Invalid min/max y-axis configuration' When Column Values Are Uniform

4 participants