Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 567720645
  • Loading branch information
blois authored and colaboratory-team committed Sep 22, 2023
1 parent c76bcb1 commit 81744a5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions google/colab/_reprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,22 @@ def _dataframe_intrinsic_repr(dataframe):
}
if ip := IPython.get_ipython():
namespace = ip.user_ns
found = False
for varname, var in namespace.items():
if dataframe is var and not varname.startswith('_'):
result['variable_name'] = varname
found = True
break
if not found:
last_line = ip.user_ns['In'][-1]
varname, dot, operator = last_line.partition('.')
if varname.isidentifier() and dot and operator.startswith('head('):
import pandas as pd

possible_df = ip.user_ns.get(varname)
if isinstance(possible_df, pd.DataFrame):
result['variable_name'] = varname
dataframe = possible_df

if summary := _summarize_dataframe(dataframe):
result['summary'] = summary
Expand Down

0 comments on commit 81744a5

Please sign in to comment.