Skip to content

Commit aca8131

Browse files
author
jorgep31415
committed
Update on "[ET] Add tsv_path to inspector_cli"
Differential Revision: [D66379005](https://our.internmc.facebook.com/intern/diff/D66379005/) [ghstack-poisoned]
1 parent 507a99f commit aca8131

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

devtools/inspector/_inspector.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,23 +1143,18 @@ def to_dataframe(
11431143
]
11441144
return pd.concat(df_list, ignore_index=True)
11451145

1146-
def print_data_tabular(
1146+
def _prepare_dataframe(
11471147
self,
1148-
file: IO[str] = sys.stdout,
11491148
include_units: bool = True,
11501149
include_delegate_debug_data: bool = False,
1151-
) -> None:
1150+
) -> pd.DataFrame:
11521151
"""
1153-
Displays the underlying EventBlocks in a structured tabular format, with each row representing an Event.
1154-
11551152
Args:
1156-
file: Which IO stream to print to. Defaults to stdout.
1157-
Not used if this is in an IPython environment such as a Jupyter notebook.
11581153
include_units: Whether headers should include units (default true)
11591154
include_delegate_debug_data: Whether to include delegate debug metadata (default false)
11601155
11611156
Returns:
1162-
None
1157+
Returns a pandas DataFrame of the Events in each EventBlock in the inspector, with additional filtering.
11631158
"""
11641159
combined_df = self.to_dataframe(include_units, include_delegate_debug_data)
11651160

@@ -1171,7 +1166,29 @@ def print_data_tabular(
11711166
]
11721167
filtered_column_df.reset_index(drop=True, inplace=True)
11731168

1174-
display_or_print_df(filtered_column_df, file)
1169+
return filtered_column_df
1170+
1171+
1172+
def print_data_tabular(
1173+
self,
1174+
file: IO[str] = sys.stdout,
1175+
include_units: bool = True,
1176+
include_delegate_debug_data: bool = False,
1177+
) -> None:
1178+
"""
1179+
Displays the underlying EventBlocks in a structured tabular format, with each row representing an Event.
1180+
1181+
Args:
1182+
file: Which IO stream to print to. Defaults to stdout.
1183+
Not used if this is in an IPython environment such as a Jupyter notebook.
1184+
include_units: Whether headers should include units (default true)
1185+
include_delegate_debug_data: Whether to include delegate debug metadata (default false)
1186+
1187+
Returns:
1188+
None
1189+
"""
1190+
df = self._prepare_dataframe(include_units, include_delegate_debug_data)
1191+
display_or_print_df(df, file)
11751192

11761193

11771194
def save_data_to_tsv(
@@ -1187,17 +1204,8 @@ def save_data_to_tsv(
11871204
Returns:
11881205
None
11891206
"""
1190-
combined_df = self.to_dataframe()
1191-
1192-
# Filter out some columns and rows for better readability when printing
1193-
filtered_column_df = combined_df.drop(columns=EXCLUDED_COLUMNS_WHEN_PRINTING)
1194-
for filter_name in EXCLUDED_EVENTS_WHEN_PRINTING:
1195-
filtered_column_df = filtered_column_df[
1196-
~filtered_column_df["event_name"].str.contains(filter_name)
1197-
]
1198-
filtered_column_df.reset_index(drop=True, inplace=True)
1199-
1200-
filtered_column_df.to_csv(file, sep="\t")
1207+
df = self._prepare_dataframe()
1208+
df.to_csv(file, sep="\t")
12011209

12021210

12031211
# TODO: write unit test

0 commit comments

Comments
 (0)