marimo
marimo copied to clipboard
RuntimeWarning when displaying DataFrame with all-NaN columns
Describe the bug
When marimo shows a pandas dataframe it sometimes gives a warning.
The warning looks like this:
python3.9/site-packages/numpy/lib/_nanfunctions_impl.py:1231: RuntimeWarning: Mean of empty slice
return np.nanmean(a, axis, out=out, keepdims=keepdims)
It comes from numpy and is about taking the mean of nans. It probably comes from the stats that marimo shows on the top of the columns, when all values in the column are nan.
Will you submit a PR?
- [ ] Yes
Environment
{
"marimo": "0.17.5",
"editable": false,
"location": "/home/horstl/project/.venv/lib/python3.9/site-packages/marimo",
"OS": "Linux",
"OS Version": "6.8.0-1041-azure",
"Processor": "x86_64",
"Python Version": "3.9.15",
"Locale": "en_US",
"Binaries": {
"Browser": "--",
"Node": "v22.20.0"
},
"Dependencies": {
"click": "8.1.8",
"docutils": "0.22.2",
"itsdangerous": "2.2.0",
"jedi": "0.19.2",
"markdown": "3.9",
"narwhals": "2.10.0",
"packaging": "24.2",
"psutil": "7.1.2",
"pygments": "2.19.2",
"pymdown-extensions": "10.16.1",
"pyyaml": "6.0.3",
"starlette": "0.49.1",
"tomlkit": "0.13.3",
"typing-extensions": "4.15.0",
"uvicorn": "0.38.0",
"websockets": "15.0.1"
},
"Optional Dependencies": {
"nbformat": "5.10.4",
"openai": "2.6.1",
"pandas": "2.2.3",
"pyarrow": "19.0.1"
},
"Experimental Flags": {}
}
Code to reproduce
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "numpy==2.0.2",
# "pandas==2.3.3",
# ]
# ///
import marimo
__generated_with = "0.17.5"
app = marimo.App()
@app.cell
def _():
import numpy as np
import pandas as pd
i = np.random.randint(10000)
size = 11
pd.DataFrame({
"id": [i] * size,
"all_nan_col": [np.nan] * size
})
return
@app.cell
def _():
import marimo as mo
return (mo,)
@app.cell(hide_code=True)
def _(mo):
mo.md(r"""
I've included the random integer part because it seems that the warning is supressed somewhere when the warning was already given on the exact same dataframe.
It also only seems to happen to dataframes with more than 10 rows.
""")
return
if __name__ == "__main__":
app.run()
This is related to: #5961