A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
chore: workaround runtime warning in pandas table column summary (#2238)
Akshay Agrawalf85edc2c9895
diff --git a/marimo/_plugins/ui/_impl/tables/pandas_table.py b/marimo/_plugins/ui/_impl/tables/pandas_table.pyindex 9a2c40197b..f24669dea9 100644--- a/marimo/_plugins/ui/_impl/tables/pandas_table.py+++ b/marimo/_plugins/ui/_impl/tables/pandas_table.py@@ -204,13 +204,17 @@ class PandasTableManagerFactory(TableManagerFactory):p95=col.quantile(0.95),)+ import numpy as np+return ColumnSummary(total=col.count(),nulls=col.isnull().sum(),min=col.min(),max=col.max(),mean=col.mean(),- median=col.median(),+ # Pandas prints an unhelpful RuntimeWarning when taking+ # the median of an all nan column+ median=col.median() if not col.isna().all() else np.nan,std=col.std(),p5=col.quantile(0.05),p25=col.quantile(0.25),diff --git a/marimo/_smoke_tests/tables/pandas_nan.py b/marimo/_smoke_tests/tables/pandas_nan.pynew file mode 100644index 0000000000..1d98bcefd1--- /dev/null+++ b/marimo/_smoke_tests/tables/pandas_nan.py@@ -0,0 +1,29 @@+# /// script+# requires-python = ">=3.10"+# dependencies = [+# "marimo",+# "numpy",+# "pandas",+# ]+# ///++import marimo++__generated_with = "0.8.11"+app = marimo.App(width="medium")+++def __():+ import marimo as mo+ import pandas as pd+ import numpy as np++ # This shouldn't print a runtime warning+ df = pd.DataFrame({"a": [1,2,3], "b": [np.nan, np.nan, np.nan]})+ df+ return df, mo, np, pd+++if __name__ == "__main__":+ app.run()