Skip to content

Commit

Permalink
Handle DataFrame/None as input to get_visualization_df (#221)
Browse files Browse the repository at this point in the history
For coherence with other `get_XXX_df` functions.
  • Loading branch information
dweindl authored Jul 26, 2023
1 parent 1aafa36 commit 52d8ab1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions petab/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,25 @@ def write_simulation_df(df: pd.DataFrame, filename: Union[str, Path]) -> None:
df.to_csv(filename, sep='\t', index=False)


def get_visualization_df(visualization_file: Union[str, Path]) -> pd.DataFrame:
def get_visualization_df(
visualization_file: Union[str, Path, pd.DataFrame, None]
) -> Union[pd.DataFrame, None]:
"""Read PEtab visualization table
Arguments:
visualization_file: URL or filename of PEtab visualization table
visualization_file:
URL or filename of PEtab visualization table to read from,
or a DataFrame or None that will be returned as is.
Returns:
Visualization DataFrame
"""
if visualization_file is None:
return None

if isinstance(visualization_file, pd.DataFrame):
return visualization_file

try:
types = {PLOT_NAME: str}
vis_spec = pd.read_csv(visualization_file, sep="\t", index_col=None,
Expand Down

0 comments on commit 52d8ab1

Please sign in to comment.