You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "nytai (via GitHub)" <gi...@apache.org> on 2026/10/13 20:19:05 UTC
[PR] fix(chart-data): convert metric columns containing "NaN" strings to numeric [superset]
nytai opened a new pull request, #45254:
URL: https://github.com/apache/superset/pull/45254
### SUMMARY
Druid serializes NaN doubles as the JSON string `"NaN"`. A metric column that mixes floats with `"NaN"` can't be converted to an Arrow array, so `SupersetResultSet` stringifies every value in it (`0.034218042` -> `'0.034218042'`).
`df_columns_to_num` is meant to recover string-encoded numerics (added for ClickHouse), but it rejects these columns: `pd.to_numeric(errors="coerce")` turns `"NaN"` into null, and the "no non-null value was lost" check treats that as a non-numeric value. The column stays as strings, and pandas post-processing (pivot, rolling, ...) fails with:
```
Could not convert string '0.034218042' to numeric
Could not convert string 'NaN' to numeric
```
This change treats `"NaN"` strings as null in that check, so these columns are converted. Columns with other non-numeric values are still left unchanged.
Legacy `viz.py` charts weren't affected because they coerce metrics unconditionally, so this surfaces when Druid charts are migrated to the ECharts / chart-data API path.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
### TESTING INSTRUCTIONS
- `pytest tests/unit_tests/common/test_dataframe_utils.py`
- Against Druid: build a chart with a metric that yields NaN for some groups (e.g. `SUM(a) / SUM(b)` where `SUM(b)` is 0) plus a post-processing step; it errors before the change and renders after.
### 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))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] 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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart-data): convert metric columns containing "NaN" strings to numeric [superset]
Posted by "nytai (via GitHub)" <gi...@apache.org>.
nytai commented on PR #45254:
URL: https://github.com/apache/superset/pull/45254#issuecomment-6154685251
Closing as this was fixed in https://github.com/apache/superset/pull/40677
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart-data): convert metric columns containing "NaN" strings to numeric [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #45254:
URL: https://github.com/apache/superset/pull/45254#issuecomment-6154737157
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/45254?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `0%` with `2 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 64.81%. Comparing base ([`8796ba1`](https://app.codecov.io/gh/apache/superset/commit/8796ba16ae75ea6d29aeda616a461418b18a7b4c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`ad54477`](https://app.codecov.io/gh/apache/superset/commit/ad544777e2eb5ed2148a0351668820e49c22798b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 1 commits behind head on master.
| [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/45254?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/common/utils/dataframe\_utils.py](https://app.codecov.io/gh/apache/superset/pull/45254?src=pr&el=tree&filepath=superset%2Fcommon%2Futils%2Fdataframe_utils.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY29tbW9uL3V0aWxzL2RhdGFmcmFtZV91dGlscy5weQ==) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/45254?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (8796ba1) and HEAD (ad54477). Click for more details.
>
> <details><summary>HEAD has 4 uploads less than BASE</summary>
>
>| Flag | BASE (8796ba1) | HEAD (ad54477) |
>|------|------|------|
>|python|7|3|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #45254 +/- ##
===========================================
- Coverage 83.23% 64.81% -18.42%
===========================================
Files 3037 3037
Lines 197880 197892 +12
Branches 46114 46116 +2
===========================================
- Hits 164708 128270 -36438
- Misses 29947 66719 +36772
+ Partials 3225 2903 -322
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/45254/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Ξ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/45254/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `35.02% <0.00%> (-0.01%)` | :arrow_down: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/45254/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/45254/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/45254/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `36.79% <0.00%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/45254/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.96% <0.00%> (-33.90%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/45254/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.85% <0.00%> (-0.01%)` | :arrow_down: |
| [unit](https://app.codecov.io/gh/apache/superset/pull/45254/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/45254?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart-data): convert metric columns containing "NaN" strings to numeric [superset]
Posted by "nytai (via GitHub)" <gi...@apache.org>.
nytai closed pull request #45254: fix(chart-data): convert metric columns containing "NaN" strings to numeric
URL: https://github.com/apache/superset/pull/45254
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart-data): convert metric columns containing "NaN" strings to numeric [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #45254:
URL: https://github.com/apache/superset/pull/45254#discussion_r4263638103
##########
superset/common/utils/dataframe_utils.py:
##########
@@ -72,9 +72,13 @@ def df_columns_to_num(df: pd.DataFrame, columns: Collection[str]) -> None:
# soft-convert a metric column to numeric only if all
# non-null values look numeric (e.g. ClickHouse returns
# SUM() results as strings). Leaves truly non-numeric
- # columns unchanged.
+ # columns unchanged. "NaN" strings count as null, since Druid
+ # serializes NaN as the JSON string "NaN".
converted = pd.to_numeric(df[col], errors="coerce")
- if converted.notna().eq(df[col].notna()).all():
+ nan_strings = df[col].map(
+ lambda value: isinstance(value, str) and value.lower() == "nan"
+ )
+ if converted.notna().eq(df[col].notna() & ~nan_strings).all():
df[col] = converted
Review Comment:
**Suggestion:** A text-valued metric containing only the literal βNaNβ now passes this check and becomes nulls, silently losing valid values in non-Druid queries.
**Assessment:** π `Major` Β· π `Occurrence: Rarely` Β· π·οΈ `Incorrect condition logic`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a6e567fa3bc54aa99c73dce17bb38be8&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a6e567fa3bc54aa99c73dce17bb38be8&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent π€ </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/common/utils/dataframe_utils.py
**Line:** 78:82
**Comment:**
*Incorrect Condition Logic: A text-valued metric containing only the literal βNaNβ now passes this check and becomes nulls, silently losing valid values in non-Druid queries.
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
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45254&comment_hash=e59e66e54e3955e306f8e29943d3b63d29fa26bb6e6c0dbfdced74ef9b36ebc4&reaction=like'>π</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45254&comment_hash=e59e66e54e3955e306f8e29943d3b63d29fa26bb6e6c0dbfdced74ef9b36ebc4&reaction=dislike'>π</a>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart-data): convert metric columns containing "NaN" strings to numeric [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #45254:
URL: https://github.com/apache/superset/pull/45254#issuecomment-6154512865
## CodeAnt PR Risk: Medium Risk
- The PR needs attention before merging because it may turn valid text-valued metrics into nulls.
- Metric columns containing numeric strings and the literal βNaNβ are coerced without checking whether βNaNβ is a Druid sentinel or valid text.
**Assessed commit:** `ad544777e2eb`
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org