Get help from the marimo community

Updated 2 months ago

How null values are rendered in tables

At a glance

The community member is exploring data and wants to see null values explicitly in the output, similar to how they are rendered in the 'plain' output. They tried using format_mapping to transform and display None rows, but it didn't work as expected. Other community members experimented with format_mapping and found that it is called twice for every element and doesn't work for 'None' elements, which they consider a bug. One community member made a pull request to apply format_mapping to None values in table formatting, and they expect the issue to be resolved in the next release.

Useful resources
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
Attachment
Screenshot_2024-12-16_at_13.30.47.png
e
s
5 comments
@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?

Plain Text
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"]))
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)
Plain Text
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},
)
`
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 ๐Ÿ™‚

https://github.com/marimo-team/marimo/issues/3208
Add a reply
Sign up and join the conversation on Discord