Spaces:
Runtime error
Runtime error
Fix Space crash on empty results CSV
Browse files52 unmodified lines53545556575838 unmodified lines97989910010110210310410510610710810920 unmodified lines1301311321331341354 unmodified lines1401411421431441452 unmodified lines14814915015115215315415515615715828 unmodified lines18718818919019119219319419519619719819920020120220352 unmodified lines"TSFM3": "Chronos-2",}def format_number(value):if isinstance(value, (int, float)):38 unmodified linesfor file in files:if file != "all_results.csv":continueframes.append(pd.read_csv(os.path.join(subdir, file)))if not frames:raise FileNotFoundError(f"No all_results.csv found under {root_dir}")df = pd.concat(frames, ignore_index=True)df = df.sort_values(by=["model", "dataset"]).reset_index(drop=True)df["model"] = df["model"].replace(LEGACY_MODEL_NAMES)df[["dataset", "frequency", "term_length"]] = df["dataset"].str.split("/", expand=True)return df20 unmodified linesds_properties = str(Path(root_dir) / "dataset_properties.csv")df = load_all_results(root_dir)if Path(ds_properties).exists():df = enrich_with_properties(df, ds_properties)4 unmodified linesdef _add_per_dataset_ranks(df: pd.DataFrame) -> pd.DataFrame:df = df.copy()group_keys = ["dataset", "term_length", "frequency"]for metric in DISPLAY_METRICS:2 unmodified linesreturn dfdef get_grouped_dfs(root_dir: str = "results",ds_properties: str | None = None,) -> dict[str, pd.DataFrame | list[str]]:df = prepare_results_df(root_dir, ds_properties)rank_cols = [f"Rank_{metric}" for metric in DISPLAY_METRICS]overall_values = df.groupby(["model"])[DISPLAY_METRICS].agg(aggregate_gmean)28 unmodified linesdef prepare_values_table(values_df: pd.DataFrame) -> pd.DataFrame:table = values_df.reset_index().rename(columns={"model": "Model"})table = format_df(table)cols = ["Model"] + [col for col in VALUE_COLUMNS if col in table.columns]return table[cols].sort_values(by=["MASE"])def prepare_ranks_table(ranks_df: pd.DataFrame) -> pd.DataFrame:table = ranks_df.reset_index().rename(columns={"model": "Model"})table = format_df(table)cols = ["Model"] + [col for col in RANK_COLUMNS if col in table.columns]return table[cols].sort_values(by=["MASE_Rank"])DOMAIN_DISPLAY = {52 unmodified lines535455565758596061626364656638 unmodified lines10510610710810911011111211311411511611711811912012112212312412512612712812913020 unmodified lines1511521531541551561571584 unmodified lines1631641651661671681691702 unmodified lines17317417517617717817918018118218318418518618718818919019119219319419519628 unmodified lines22522622722822923023123223323423523623723823924024124224324424524624724824925025152 unmodified lines"TSFM3": "Chronos-2",}RESULT_COLUMNS = ["dataset","model",*METRIC_COLUMNS,"domain","num_variates",]def format_number(value):if isinstance(value, (int, float)):38 unmodified linesfor file in files:if file != "all_results.csv":continueframe = pd.read_csv(os.path.join(subdir, file))if frame.empty:continueframes.append(frame)if not frames:return pd.DataFrame(columns=RESULT_COLUMNS)df = pd.concat(frames, ignore_index=True)df = df.dropna(subset=["dataset"], how="any")df = df[df["dataset"].astype(str).str.len() > 0]if df.empty:return pd.DataFrame(columns=RESULT_COLUMNS)df = df.sort_values(by=["model", "dataset"]).reset_index(drop=True)df["model"] = df["model"].replace(LEGACY_MODEL_NAMES)parts = df["dataset"].astype(str).str.split("/", expand=True)if parts.shape[1] < 3:for idx in range(parts.shape[1], 3):parts[idx] = "short" if idx == 2 else ""df["dataset"] = parts[0]df["frequency"] = parts[1]df["term_length"] = parts[2]return df20 unmodified linesds_properties = str(Path(root_dir) / "dataset_properties.csv")df = load_all_results(root_dir)if df.empty:return dfif Path(ds_properties).exists():df = enrich_with_properties(df, ds_properties)4 unmodified linesdef _add_per_dataset_ranks(df: pd.DataFrame) -> pd.DataFrame:if df.empty:return dfdf = df.copy()group_keys = ["dataset", "term_length", "frequency"]for metric in DISPLAY_METRICS:2 unmodified linesreturn dfdef _empty_grouped_dfs() -> dict[str, pd.DataFrame | list[str]]:rank_cols = [f"Rank_{metric}" for metric in DISPLAY_METRICS]return {"overall_values": pd.DataFrame(columns=DISPLAY_METRICS),"overall_ranks": pd.DataFrame(columns=rank_cols),"dataset_values": {},"dataset_ranks": {},"datasets": [],}def get_grouped_dfs(root_dir: str = "results",ds_properties: str | None = None,) -> dict[str, pd.DataFrame | list[str]]:df = prepare_results_df(root_dir, ds_properties)if df.empty:return _empty_grouped_dfs()rank_cols = [f"Rank_{metric}" for metric in DISPLAY_METRICS]overall_values = df.groupby(["model"])[DISPLAY_METRICS].agg(aggregate_gmean)28 unmodified linesdef prepare_values_table(values_df: pd.DataFrame) -> pd.DataFrame:if values_df is None or values_df.empty:return pd.DataFrame(columns=["Model"] + VALUE_COLUMNS)table = values_df.reset_index().rename(columns={"model": "Model"})table = format_df(table)cols = ["Model"] + [col for col in VALUE_COLUMNS if col in table.columns]table = table[cols]if "MASE" in table.columns and not table["MASE"].isna().all():return table.sort_values(by=["MASE"])return tabledef prepare_ranks_table(ranks_df: pd.DataFrame) -> pd.DataFrame:if ranks_df is None or ranks_df.empty:return pd.DataFrame(columns=["Model"] + RANK_COLUMNS)table = ranks_df.reset_index().rename(columns={"model": "Model"})table = format_df(table)cols = ["Model"] + [col for col in RANK_COLUMNS if col in table.columns]table = table[cols]if "MASE_Rank" in table.columns and not table["MASE_Rank"].isna().all():return table.sort_values(by=["MASE_Rank"])return tableDOMAIN_DISPLAY = {
src/utils.py+53-5