seb
seb•2mo ago

How null values are rendered in tables

Hi everyone, Sometimes during exploration of data, seeing null values matters. In the above example, I would like to see them explicitly, the same way it's rendered in the 'plain' output. Is that possible ? Thanks a lot for the great job on marimo
No description
6 Replies
Hall
Hall•2mo ago
Someone will reply to you shortly. In the meantime, this might help:
eugene
eugene•2mo ago
@Myles Scolnick I think this should work: use format_mapping to transform and display None rows explicitly, but it doesn't. The lambda function defined seems correct, but in the table it's still nothing. Is this a bug?
import polars as pl

df = pl.DataFrame(
{
"a": [[None, 1, 2, 3], [4, 5, 6, 7], None],
}
).with_row_index("i")

mo.ui.table(
df,
format_mapping={"a": lambda x: "None" if x is None else x},
)

list(map(lambda x: "None" if x is None else x, df["a"]))
import polars as pl

df = pl.DataFrame(
{
"a": [[None, 1, 2, 3], [4, 5, 6, 7], None],
}
).with_row_index("i")

mo.ui.table(
df,
format_mapping={"a": lambda x: "None" if x is None else x},
)

list(map(lambda x: "None" if x is None else x, df["a"]))
eugene
eugene•2mo ago
No description
seb
sebOP•2mo ago
Well, I experimented with format_mapping, and managed (for my polars df) to get inner null elements printed. But two odd things append with format_mapping: - it's called twice for every elements - it's not called for 'None' elements ( the bug you're talking about @eugene)
df = pl.DataFrame(
{
"a": [[None, 1, 2, 3], [4, 5, 6, 7], None],
}
)

def fmt_mapping(x):
print(f"CALLED FOR {x}")
if isinstance(x,pl.Series):
return x.cast(pl.String).fill_null("null").str.join(",")
return x

mo.ui.table(
df,
format_mapping={"a": fmt_mapping},
)
df = pl.DataFrame(
{
"a": [[None, 1, 2, 3], [4, 5, 6, 7], None],
}
)

def fmt_mapping(x):
print(f"CALLED FOR {x}")
if isinstance(x,pl.Series):
return x.cast(pl.String).fill_null("null").str.join(",")
return x

mo.ui.table(
df,
format_mapping={"a": fmt_mapping},
)
`
seb
sebOP•2mo ago
No description
eugene
eugene•2mo ago
Yeah, the format_mapping is skipping None values. I made a PR to apply format_mapping to None values in table formatting. You should be able to use format_mapping to print the null elements in the next release. I made an issue to track format_mapping is called twice for every elements, thanks for your experiment 🙂
GitHub
format_mapping called twice for every elements · Issue #3208 · mari...
Describe the bug format_mapping is called twice for every elements Environment { "marimo": "0.10.5", "OS": "Darwin", "OS Version": "24.0.0&quo...

Did you find this page helpful?