- 
                Notifications
    You must be signed in to change notification settings 
- Fork 748
improve performant table charts, remove feat flag #6892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| The latest updates on your projects. Learn more about Vercel for GitHub. 
 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The desired behavior for a histogram is that each bin represents the same range. Is that what is meant by
When using temporal type, the bar widths are proportioned to the values.
and if so, then we shouldn't make this change. But I agree that the plots in the "before" image look ugly.
Can you explain in more detail what the original problem is and how this change fixes it? I don't quite understand.
| @Light2Dark , additionally can you provide a sample notebook (in  | 
| 
 I should preface by saying this is a bug when turning on  I like the proportioned bars idea, but it looks ugly when one bar takes up a lot of space. This alternative, I think simplest and matches non feature flag behaviour. I'm not sure if narwhals v2 has changed anything to offer better alternatives for temporal charting. will create a sample notebook! | 
| Thanks so much for the additional context! 
 Got it. 
 For histograms (and anything in our product conveying data / data distributions), we should prioritize correctness over aesthetics; that said I'm happy to look at the sample notebook, that'll make this a lot more concrete for me. 
 Thank you! | 
| I created a notebook here:  I think we can get this in for the following release (not today) | 
87c8d51    to
    02d42a0      
    Compare
  
    6ae631b    to
    4f85750      
    Compare
  
    | 
 Taking a look, thank you for putting this together | 
| Hmm, it shouldn't be inconsistent 🤔. This is the raw bin calculation [
  "BinValue(bin_start=1, bin_end=2.0, count=6)",
  "BinValue(bin_start=2.0, bin_end=3.0, count=5)",
  "BinValue(bin_start=3.0, bin_end=4.0, count=6)",
  "BinValue(bin_start=4.0, bin_end=5.0, count=8)",
  "BinValue(bin_start=5.0, bin_end=6.0, count=0)",
  "BinValue(bin_start=6.0, bin_end=7.0, count=0)",
  "BinValue(bin_start=7.0, bin_end=8.0, count=1)",
  "BinValue(bin_start=8.0, bin_end=9.0, count=1)",
  "BinValue(bin_start=9.0, bin_end=10.0, count=1)"
]Looks like narwhals uses left-inclusive, right-inclusive for the first bin (to capture the minimum), and then left-inclusive, right exclusive for the rest. So, 1-2 has six values. But 2-3 doesn't include the last 3 so five values. python code: data = [1, 1, 1, 1, 1, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,  8, 9, 10] 
df = pl.DataFrame({"data": data})
from marimo._plugins.ui._impl.tables.narwhals_table import NarwhalsTableManager
DEFAULT_BIN_SIZE = 9
manager = NarwhalsTableManager.from_dataframe(df)
manager.get_bin_values("data", DEFAULT_BIN_SIZE)marking as draft because I realize the narwhals hist API is marked unstable | 
| 
 Got it, thank you for explaining. That should be okay then, really appreciate the explanation. 
 @Light2Dark, want to make an issue on the Narwhals repo, explain our use case, and ask Marco to what extent we can rely on the API, or if he can provide us a semi-private stable API? Hopefully we can find a solution | 
| 
 I could do that, we can also fallback to our legacy spec and handling. I removed it because it was cleaner. I think fine to fallback. edit, actually we lose some perf by fallback. let me check with narwhals. narwhals-dev/narwhals#3249 | 
…6895) <!-- Provide a concise summary of what this pull request is addressing. If this PR fixes any issues, list them here by number (e.g., Fixes --> Removes parameters used for performant_table_charts. We can use it by default. Removes old data param. Also enables string charts for <20k rows which imo is reasonable.  <!-- Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [ ] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected.
<!-- Provide a concise summary of what this pull request is addressing. If this PR fixes any issues, list them here by number (e.g., Fixes --> For narwhals, get_bin_values is marked as unstable. So, we should fallback to legacy data and spec handling. https://narwhals-dev.github.io/narwhals/api-reference/series/#narwhals.series.Series.hist <!-- Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [x] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected.
88e3184    to
    7d52121      
    Compare
  
    | @dataclass | ||
| class ColumnSummaries: | ||
| # If precomputed aggregations fail, we fallback to chart data | ||
| data: Union[JSONType, str] | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to be optional? or would the json type be empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, don't need to, JSONType has None:
    JSONType: TypeAlias = Union[
        Mapping[str, "JSONType"],
        Sequence["JSONType"],
        str,
        int,
        float,
        bool,
        object,
        MIME,  # MIME is a JSONType since we have a custom JSONEncoder for it
        None,
    ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work!
| merging this in, can test during bug bash | 


📝 Summary
Some of these changes are opinionated so feel free to disagree.
before:

after:
CleanShot.2025-10-24.at.11.37.56.mp4
When using temporal type, the bar widths are proportioned to the values. this can make some bars have very small widths. The fix is to use ordinal. Additionally, there is better hovering behaviour.
🔍 Description of Changes
📋 Checklist