aminghadersohi opened a new pull request, #39916:
URL: https://github.com/apache/superset/pull/39916
### SUMMARY
When a dataset contains NULL values, they are represented as `float('nan')`
after numeric conversion. The ASCII bar chart renderers passed NaN directly
into `int()`, raising `ValueError: cannot convert float NaN to integer`.
Root cause: `_generate_ascii_bar_chart` and `_extract_time_series_data`
accepted `float('nan')` values through the `isinstance(val, (int, float))`
check, which returns `True` for NaN. The NaN then propagated into `max()` /
normalization calculations, causing the crash at `int(normalized *
max_bar_width)`.
Three-layer fix:
1. **Extraction-time filtering** — `_generate_ascii_bar_chart` and
`_extract_time_series_data` now call `_is_nan_value()` (already defined in the
module) before accepting a numeric value, silently skipping NaN rows.
2. **Defence-in-depth guards** — `_generate_horizontal_bar_chart` and
`_generate_vertical_bar_chart` check `_is_nan_value(normalized)` before the
`int()` call, treating NaN bar size as 0 (no bar drawn).
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — ASCII chart output; crash prevented.
### TESTING INSTRUCTIONS
1. Create a dataset with at least one NULL value in a numeric column.
2. Render a bar or line chart via the MCP `get_chart_preview` tool.
3. Before this fix: `ValueError: cannot convert float NaN to integer`.
4. After this fix: chart renders with NaN rows silently skipped.
Unit tests added in
`tests/unit_tests/mcp_service/chart/test_ascii_charts.py` covering bar, column,
line, and timeseries bar chart types with NaN and `None` values.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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]