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
feat: show rows, columns of truncated dataframes (#455)
Akshay Agrawal1e6e53cbf657
diff --git a/marimo/_cli/envinfo.py b/marimo/_cli/envinfo.pyindex 3cec190945..e4e906f671 100644--- a/marimo/_cli/envinfo.py+++ b/marimo/_cli/envinfo.py@@ -15,7 +15,7 @@ def get_system_info() -> dict[str, Union[str, dict[str, str]]]:"marimo": __version__,"OS": platform.system(),"OS Version": platform.release(),- # e.g., x86 or arm+ # e.g., x86 or arm"Processor": platform.processor(),"Python Version": platform.python_version(),}diff --git a/marimo/_output/formatters/pandas_formatters.py b/marimo/_output/formatters/pandas_formatters.pyindex d563ae3968..a9e9ebc8c1 100644--- a/marimo/_output/formatters/pandas_formatters.py+++ b/marimo/_output/formatters/pandas_formatters.py@@ -17,6 +17,7 @@ class PandasFormatter(FormatterFactory):pd.set_option("display.max_rows", 10)pd.set_option("display.max_columns", 20)+ pd.set_option("display.show_dimensions", "truncate")from marimo._output import formatting@@ -24,19 +25,45 @@ class PandasFormatter(FormatterFactory):def _show_dataframe(df: pd.DataFrame) -> tuple[str, str]:max_rows = pd.get_option("display.max_rows")max_columns = pd.get_option("display.max_columns")+ show_dimensions_option = pd.get_option("display.show_dimensions")+ if show_dimensions_option == "truncate":+ show_dimensions = (+ len(df.index) > max_rows or len(df.columns) > max_columns+ )+ elif show_dimensions_option:+ show_dimensions = True+ else:+ show_dimensions = False+# Flatten the HTML to avoid indentation issues when# interpolating into other HTML/Markdown with an f-stringreturn ("text/html",flatten_string(- df.to_html(max_rows=max_rows, max_cols=max_columns)+ df.to_html(+ max_rows=max_rows,+ max_cols=max_columns,+ show_dimensions=show_dimensions,+ )),)@formatting.formatter(pd.Series)def _show_series(series: pd.Series[Any]) -> tuple[str, str]:max_rows = pd.get_option("display.max_rows")+ show_dimensions_option = pd.get_option("display.show_dimensions")+ if show_dimensions_option == "truncate":+ show_dimensions = len(series.index) > max_rows+ elif show_dimensions_option:+ show_dimensions = True+ else:+ show_dimensions = False+return ("text/html",- flatten_string(series.to_frame().to_html(max_rows=max_rows)),+ flatten_string(+ series.to_frame().to_html(+ max_rows=max_rows, show_dimensions=show_dimensions+ )+ ),)