bulletmark
bulletmark3w ago

mo.ui.altair_chart() reinterpreting str x-axis as datetime.

I have a altair.Chart() which outputs fine if I render it directly but if I wrap it in a mo.ui.altair_chart() then the string x-axis values which are versions of the form "x.y.x" are getting evaluated as datetimes so the graph is exactly the same except the x-values are erroneously shown as datetimes. How can I stop this? See https://imgur.com/a/0wFfaYk. First graph is raw altair graph, second is wrapped graph.
9 Replies
Hall
Hall3w ago
Someone will reply to you shortly. In the meantime, this might help:
bulletmark
bulletmarkOP3w ago
I've created a trivial example of this as follows. Could this be a marimo bug?
import marimo

__generated_with = "0.10.9"
app = marimo.App(width="medium")

@app.cell
def _():
import pandas as _pd
import altair as _alt
_d = _pd.DataFrame({"Version": ["1.1.1", "2.2.2"], "Days": [3, 4]})

ct = _alt.Chart(_d).mark_bar().encode(
x='Version',
y='Days',
)
ct
return ct,

@app.cell
def _(ct):
import marimo as _mo
_mo.ui.altair_chart(ct)
return

if __name__ == "__main__":
app.run()
import marimo

__generated_with = "0.10.9"
app = marimo.App(width="medium")

@app.cell
def _():
import pandas as _pd
import altair as _alt
_d = _pd.DataFrame({"Version": ["1.1.1", "2.2.2"], "Days": [3, 4]})

ct = _alt.Chart(_d).mark_bar().encode(
x='Version',
y='Days',
)
ct
return ct,

@app.cell
def _(ct):
import marimo as _mo
_mo.ui.altair_chart(ct)
return

if __name__ == "__main__":
app.run()
Myles Scolnick
If you don’t wrap it in an altair_chart, is there still a bug? Thanks for the minimal repro, we can fix this if it’s a marimo bug
bulletmark
bulletmarkOP3w ago
Look at the image I posted above, 1st image is my app just rendering the chart directly as chart, the second image is merely wrapping it in mo.ui.altair_chart(chart).
Myles Scolnick
Ah yea I see now. Thanks, this is a bug in marimo then. We auto-infer the data type and we should not for charts
bulletmark
bulletmarkOP3w ago
So I should raise an issue?
Myles Scolnick
That would be great, thank you very much
bulletmark
bulletmarkOP3w ago
GitHub
mo.ui.altair_chart() reinterpreting string x-axis as datetime · Iss...
Describe the bug I have a altair.Chart() which outputs fine if I render it directly but if I wrap it in a mo.ui.altair_chart() then the string x-axis values which are versions of the form "x.y...
Myles Scolnick
just wanted to followup this was fixed in https://github.com/marimo-team/marimo/pull/3335
GitHub
fix: only parse valid ISO date strings in DATE_MIDDLEWARE by devin-...
Fixes #3330 Added strict ISO date string validation in DATE_MIDDLEWARE to prevent incorrect parsing of version-like strings (e.g., "1.1.1") as dates. This ensures we maintain cons...

Did you find this page helpful?