Skip to content

[ET] Add tsv_path to inspector_cli #7046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions devtools/inspector/_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,23 +1143,18 @@ def to_dataframe(
]
return pd.concat(df_list, ignore_index=True)

def print_data_tabular(
def _prepare_dataframe(
self,
file: IO[str] = sys.stdout,
include_units: bool = True,
include_delegate_debug_data: bool = False,
) -> None:
) -> pd.DataFrame:
"""
Displays the underlying EventBlocks in a structured tabular format, with each row representing an Event.
Args:
file: Which IO stream to print to. Defaults to stdout.
Not used if this is in an IPython environment such as a Jupyter notebook.
include_units: Whether headers should include units (default true)
include_delegate_debug_data: Whether to include delegate debug metadata (default false)
Returns:
None
Returns a pandas DataFrame of the Events in each EventBlock in the inspector, with additional filtering.
"""
combined_df = self.to_dataframe(include_units, include_delegate_debug_data)

Expand All @@ -1171,7 +1166,44 @@ def print_data_tabular(
]
filtered_column_df.reset_index(drop=True, inplace=True)

display_or_print_df(filtered_column_df, file)
return filtered_column_df

def print_data_tabular(
self,
file: IO[str] = sys.stdout,
include_units: bool = True,
include_delegate_debug_data: bool = False,
) -> None:
"""
Displays the underlying EventBlocks in a structured tabular format, with each row representing an Event.
Args:
file: Which IO stream to print to. Defaults to stdout.
Not used if this is in an IPython environment such as a Jupyter notebook.
include_units: Whether headers should include units (default true)
include_delegate_debug_data: Whether to include delegate debug metadata (default false)
Returns:
None
"""
df = self._prepare_dataframe(include_units, include_delegate_debug_data)
display_or_print_df(df, file)

def save_data_to_tsv(
self,
file: IO[str],
) -> None:
"""
Stores the underlying EventBlocks in tsv format to facilitate copy-paste into spreadsheets.
Args:
file: Which IO stream to print to. Do not use stdout, as tab separator is not preserved.
Returns:
None
"""
df = self._prepare_dataframe()
df.to_csv(file, sep="\t")

# TODO: write unit test
def find_total_for_module(self, module_name: str) -> float:
Expand Down
7 changes: 7 additions & 0 deletions devtools/inspector/inspector_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def main() -> None:
required=False,
help="Provide an optional buffer file path.",
)
parser.add_argument(
"--tsv_path",
required=False,
help="Provide an optional tsv file path.",
)
parser.add_argument("--compare_results", action="store_true")

args = parser.parse_args()
Expand All @@ -55,6 +60,8 @@ def main() -> None:
target_time_scale=TimeScale(args.target_time_scale),
)
inspector.print_data_tabular()
if args.tsv_path:
inspector.save_data_to_tsv(args.tsv_path)
if args.compare_results:
for event_block in inspector.event_blocks:
if event_block.name == "Execute":
Expand Down
Loading