You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "michael-s-molina (via GitHub)" <gi...@apache.org> on 2025/02/13 18:31:26 UTC

[PR] fix: Decimal values for Histogram bins [superset]

michael-s-molina opened a new pull request, #32253:
URL: https://github.com/apache/superset/pull/32253

   ### SUMMARY
   Users reported that Histogram bins were always rounded to integers and that was problematic for specific types of analysis. This PR fixes that problem by giving users the flexibility to configure the x-axis and y-axis formats using Explore controls.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   https://github.com/user-attachments/assets/0f9c3ce6-29e5-4f90-8320-4e7e67c8cee9
   
   ### TESTING INSTRUCTIONS
   Check the you're able to change x-axis and y-axis formats.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] 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: Decimal values for Histogram bins [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #32253:
URL: https://github.com/apache/superset/pull/32253#issuecomment-2657432060

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/32253?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Project coverage is 65.52%. Comparing base [(`76d897e`)](https://app.codecov.io/gh/apache/superset/commit/76d897eaa2f9e137102bc194c2e3109c29d0348f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`3f8077c`)](https://app.codecov.io/gh/apache/superset/commit/3f8077cb96428becaab423e635a222a1dada9133?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 1445 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #32253      +/-   ##
   ==========================================
   + Coverage   60.48%   65.52%   +5.03%     
   ==========================================
     Files        1931      546    -1385     
     Lines       76236    39097   -37139     
     Branches     8568        0    -8568     
   ==========================================
   - Hits        46114    25617   -20497     
   + Misses      28017    13480   -14537     
   + Partials     2105        0    -2105     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/32253/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/32253/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `48.49% <ø> (-0.67%)` | :arrow_down: |
   | [javascript](https://app.codecov.io/gh/apache/superset/pull/32253/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/32253/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `53.02% <ø> (-0.78%)` | :arrow_down: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/32253/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `65.52% <ø> (+2.03%)` | :arrow_up: |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/32253/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `61.06% <ø> (+3.44%)` | :arrow_up: |
   
   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 Sentry](https://app.codecov.io/gh/apache/superset/pull/32253?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).
   


-- 
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: Decimal values for Histogram bins [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina merged PR #32253:
URL: https://github.com/apache/superset/pull/32253


-- 
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: Decimal values for Histogram bins [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #32253:
URL: https://github.com/apache/superset/pull/32253#discussion_r1955046878


##########
superset/utils/pandas_postprocessing/histogram.py:
##########
@@ -60,8 +60,7 @@ def histogram(
 
     # convert the bin edges to strings
     bin_edges_str = [
-        f"{int(bin_edges[i])} - {int(bin_edges[i+1])}"
-        for i in range(len(bin_edges) - 1)
+        f"{bin_edges[i]} - {bin_edges[i+1]}" for i in range(len(bin_edges) - 1)

Review Comment:
   @korbit-ai This is intentional to allow the frontend code to handle label formatting.



-- 
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: Decimal values for Histogram bins [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #32253:
URL: https://github.com/apache/superset/pull/32253#discussion_r1955038154


##########
superset-frontend/plugins/plugin-chart-echarts/src/Histogram/transformProps.ts:
##########
@@ -58,19 +59,33 @@ export default function transformProps(
     showLegend,
     showValue,
     sliceId,
+    xAxisFormat,
     xAxisTitle,
     yAxisTitle,
+    yAxisFormat,
   } = formData;
   const { data } = queriesData[0];
   const colorFn = CategoricalColorNamespace.getScale(colorScheme);
-  const formatter = getNumberFormatter(
-    normalize ? NumberFormats.FLOAT_2_POINT : NumberFormats.INTEGER,
-  );
+
+  const formatter = (format: string) =>
+    getValueFormatter(
+      column,
+      currencyFormats,
+      columnFormats,
+      format,
+      undefined,
+    );
+  const xAxisFormatter = formatter(xAxisFormat);
+  const yAxisFormatter = formatter(yAxisFormat);
+
   const percentFormatter = getPercentFormatter(NumberFormats.PERCENT_2_POINT);
   const groupbySet = new Set(groupby);
-  const xAxisData: string[] = Object.keys(data[0]).filter(
-    key => !groupbySet.has(key),
-  );
+  const xAxisData: string[] = Object.keys(data[0])
+    .filter(key => !groupbySet.has(key))
+    .map(key => {
+      const array = key.split(' - ').map(value => parseFloat(value));

Review Comment:
   We don't expect non-numbers and in such case NaN will be a good representation.



-- 
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: Decimal values for Histogram bins [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #32253:
URL: https://github.com/apache/superset/pull/32253#discussion_r1955036729


##########
superset/utils/pandas_postprocessing/histogram.py:
##########
@@ -60,8 +60,7 @@ def histogram(
 
     # convert the bin edges to strings
     bin_edges_str = [
-        f"{int(bin_edges[i])} - {int(bin_edges[i+1])}"
-        for i in range(len(bin_edges) - 1)
+        f"{bin_edges[i]} - {bin_edges[i+1]}" for i in range(len(bin_edges) - 1)

Review Comment:
   This is intentional to allow the frontend code to handle label formatting.



-- 
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: Decimal values for Histogram bins [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #32253:
URL: https://github.com/apache/superset/pull/32253#discussion_r1955034951


##########
superset/utils/pandas_postprocessing/histogram.py:
##########
@@ -60,8 +60,7 @@ def histogram(
 
     # convert the bin edges to strings
     bin_edges_str = [
-        f"{int(bin_edges[i])} - {int(bin_edges[i+1])}"
-        for i in range(len(bin_edges) - 1)
+        f"{bin_edges[i]} - {bin_edges[i+1]}" for i in range(len(bin_edges) - 1)

Review Comment:
   ### Uncontrolled decimal precision in bin labels <sub>![category Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The bin edge values are now displayed with full decimal precision, which can lead to excessively long and unwieldy labels with many decimal places.
   
   ###### Why this matters
   Without proper decimal place formatting, bin labels could become very long (e.g., '3.141592653589793 - 4.141592653589793'), making the visualization harder to read and interpret.
   
   ###### Suggested change ∙ *Feature Preview*
   Add decimal place formatting to the bin edge values:
   ```python
   f"{bin_edges[i]:.2f} - {bin_edges[i+1]:.2f}"
   ```
   
   
   </details>
   
   <sub>
   
   [![Report a problem with this comment](https://img.shields.io/badge/Report%20a%20problem%20with%20this%20comment-gray.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmNWVjMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10cmlhbmdsZS1hbGVydCI+PHBhdGggZD0ibTIxLjczIDE4LTgtMTRhMiAyIDAgMCAwLTMuNDggMGwtOCAxNEEyIDIgMCAwIDAgNCAyMWgxNmEyIDIgMCAwIDAgMS43My0zIi8+PHBhdGggZD0iTTEyIDl2NCIvPjxwYXRoIGQ9Ik0xMiAxN2guMDEiLz48L3N2Zz4=)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0efb854b-626f-474b-a2f3-cef3993db06a?suggestedFixEnabled=true)
   
   💬 Chat with Korbit by mentioning @korbit-ai.
   </sub>
   
   <!--- korbi internal id:ab44e544-b543-4097-8635-86ce1147a214 -->
   



##########
superset-frontend/plugins/plugin-chart-echarts/src/Histogram/transformProps.ts:
##########
@@ -58,19 +59,33 @@ export default function transformProps(
     showLegend,
     showValue,
     sliceId,
+    xAxisFormat,
     xAxisTitle,
     yAxisTitle,
+    yAxisFormat,
   } = formData;
   const { data } = queriesData[0];
   const colorFn = CategoricalColorNamespace.getScale(colorScheme);
-  const formatter = getNumberFormatter(
-    normalize ? NumberFormats.FLOAT_2_POINT : NumberFormats.INTEGER,
-  );
+
+  const formatter = (format: string) =>
+    getValueFormatter(
+      column,
+      currencyFormats,
+      columnFormats,
+      format,
+      undefined,
+    );
+  const xAxisFormatter = formatter(xAxisFormat);
+  const yAxisFormatter = formatter(yAxisFormat);
+
   const percentFormatter = getPercentFormatter(NumberFormats.PERCENT_2_POINT);
   const groupbySet = new Set(groupby);
-  const xAxisData: string[] = Object.keys(data[0]).filter(
-    key => !groupbySet.has(key),
-  );
+  const xAxisData: string[] = Object.keys(data[0])
+    .filter(key => !groupbySet.has(key))
+    .map(key => {
+      const array = key.split(' - ').map(value => parseFloat(value));

Review Comment:
   ### Missing Error Handling for Bin Edge Parsing <sub>![category Error Handling](https://img.shields.io/badge/Error%20Handling-ea580c)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The code assumes bin edges will always be valid numbers that can be parsed with parseFloat, without any error handling for malformed data.
   
   ###### Why this matters
   If the data contains malformed bin edges that can't be parsed to floats, it will result in NaN values and potentially crash the visualization or display incorrect data.
   
   ###### Suggested change ∙ *Feature Preview*
   Add error handling to safely parse bin edges and provide fallback values if needed:
   ```typescript
   const array = key.split(' - ').map(value => {
     const parsed = parseFloat(value);
     if (Number.isNaN(parsed)) {
       console.warn(`Invalid bin edge value: ${value}`);
       return 0; // or other appropriate fallback
     }
     return parsed;
   });
   ```
   
   
   </details>
   
   <sub>
   
   [![Report a problem with this comment](https://img.shields.io/badge/Report%20a%20problem%20with%20this%20comment-gray.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmNWVjMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10cmlhbmdsZS1hbGVydCI+PHBhdGggZD0ibTIxLjczIDE4LTgtMTRhMiAyIDAgMCAwLTMuNDggMGwtOCAxNEEyIDIgMCAwIDAgNCAyMWgxNmEyIDIgMCAwIDAgMS43My0zIi8+PHBhdGggZD0iTTEyIDl2NCIvPjxwYXRoIGQ9Ik0xMiAxN2guMDEiLz48L3N2Zz4=)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/8cdebb56-dcdd-4b25-89fe-6acf6eca5c11?suggestedFixEnabled=true)
   
   💬 Chat with Korbit by mentioning @korbit-ai.
   </sub>
   
   <!--- korbi internal id:a29b20b6-84cf-4616-bd26-7775b8242ce3 -->
   



-- 
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: Decimal values for Histogram bins [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #32253:
URL: https://github.com/apache/superset/pull/32253#discussion_r1955036729


##########
superset/utils/pandas_postprocessing/histogram.py:
##########
@@ -60,8 +60,7 @@ def histogram(
 
     # convert the bin edges to strings
     bin_edges_str = [
-        f"{int(bin_edges[i])} - {int(bin_edges[i+1])}"
-        for i in range(len(bin_edges) - 1)
+        f"{bin_edges[i]} - {bin_edges[i+1]}" for i in range(len(bin_edges) - 1)

Review Comment:
   @korbit-ai This is intentional to allow the frontend code to handle label formatting.



##########
superset-frontend/plugins/plugin-chart-echarts/src/Histogram/transformProps.ts:
##########
@@ -58,19 +59,33 @@ export default function transformProps(
     showLegend,
     showValue,
     sliceId,
+    xAxisFormat,
     xAxisTitle,
     yAxisTitle,
+    yAxisFormat,
   } = formData;
   const { data } = queriesData[0];
   const colorFn = CategoricalColorNamespace.getScale(colorScheme);
-  const formatter = getNumberFormatter(
-    normalize ? NumberFormats.FLOAT_2_POINT : NumberFormats.INTEGER,
-  );
+
+  const formatter = (format: string) =>
+    getValueFormatter(
+      column,
+      currencyFormats,
+      columnFormats,
+      format,
+      undefined,
+    );
+  const xAxisFormatter = formatter(xAxisFormat);
+  const yAxisFormatter = formatter(yAxisFormat);
+
   const percentFormatter = getPercentFormatter(NumberFormats.PERCENT_2_POINT);
   const groupbySet = new Set(groupby);
-  const xAxisData: string[] = Object.keys(data[0]).filter(
-    key => !groupbySet.has(key),
-  );
+  const xAxisData: string[] = Object.keys(data[0])
+    .filter(key => !groupbySet.has(key))
+    .map(key => {
+      const array = key.split(' - ').map(value => parseFloat(value));

Review Comment:
   @korbit-ai We don't expect non-numbers and in such case NaN will be a good representation.



-- 
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: Decimal values for Histogram bins [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #32253:
URL: https://github.com/apache/superset/pull/32253#discussion_r1955047130


##########
superset/utils/pandas_postprocessing/histogram.py:
##########
@@ -60,8 +60,7 @@ def histogram(
 
     # convert the bin edges to strings
     bin_edges_str = [
-        f"{int(bin_edges[i])} - {int(bin_edges[i+1])}"
-        for i in range(len(bin_edges) - 1)
+        f"{bin_edges[i]} - {bin_edges[i+1]}" for i in range(len(bin_edges) - 1)

Review Comment:
   Thanks for the clarification @michael-s-molina. If formatting is handle in the frontend then it makes sense to keep full precision here. Please do make sure the frontend feature handles very long decimal precision properly to avoid unwieldy labels.



-- 
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: Decimal values for Histogram bins [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #32253:
URL: https://github.com/apache/superset/pull/32253#discussion_r1955036729


##########
superset/utils/pandas_postprocessing/histogram.py:
##########
@@ -60,8 +60,7 @@ def histogram(
 
     # convert the bin edges to strings
     bin_edges_str = [
-        f"{int(bin_edges[i])} - {int(bin_edges[i+1])}"
-        for i in range(len(bin_edges) - 1)
+        f"{bin_edges[i]} - {bin_edges[i+1]}" for i in range(len(bin_edges) - 1)

Review Comment:
   @korbit-ai This is intentional to allow the frontend code to handle label formatting.



-- 
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