From 94f9165a988c2c4e64c5b7b27ddb4efad7f13277 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 3 Nov 2024 10:06:18 +0200 Subject: [PATCH 1/2] fixed issue 246 (vertipaq) --- src/sempy_labs/_vertipaq.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/sempy_labs/_vertipaq.py b/src/sempy_labs/_vertipaq.py index ffdb7300..13f13d57 100644 --- a/src/sempy_labs/_vertipaq.py +++ b/src/sempy_labs/_vertipaq.py @@ -412,18 +412,19 @@ def vertipaq_analyzer( export_Model = dfModel.copy() def _style_columns_based_on_types(dataframe: pd.DataFrame, column_type_mapping): - - format_mapping = { - "int": "{:,}", - "pct": "{:.2f}%", - "": "{}", + # Define formatting functions based on the type mappings + format_funcs = { + "int": lambda x: "{:,}".format(x) if pd.notnull(x) else "", + "pct": lambda x: "{:.2f}%".format(x) if pd.notnull(x) else "", + "": lambda x: "{}".format(x), } - format_dict = { - col: format_mapping[dt] for col, dt in column_type_mapping.items() - } + # Apply the formatting function to each column based on its specified type + for col, dt in column_type_mapping.items(): + if dt in format_funcs: + dataframe[col] = dataframe[col].map(format_funcs[dt]) - return dataframe.style.format(format_dict) + return dataframe dfModel = _style_columns_based_on_types( dfModel, @@ -979,7 +980,8 @@ def import_vertipaq_analyzer(folder_path: str, file_name: str): dfs = {} for file_name in zip_ref.namelist(): df = pd.read_csv(extracted_dir + "/" + file_name) - dfs[file_name] = df + df_name = file_name[:-4] + dfs[df_name] = df visualize_vertipaq(dfs) From fecf4da70b3f3e9ff3b520588e1946c373806e29 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 4 Nov 2024 14:39:43 +0200 Subject: [PATCH 2/2] update per comment --- src/sempy_labs/_vertipaq.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sempy_labs/_vertipaq.py b/src/sempy_labs/_vertipaq.py index 13f13d57..40dbac62 100644 --- a/src/sempy_labs/_vertipaq.py +++ b/src/sempy_labs/_vertipaq.py @@ -21,6 +21,7 @@ from typing import Optional from sempy._utils._log import log import sempy_labs._icons as icons +from pathlib import Path @log @@ -980,7 +981,8 @@ def import_vertipaq_analyzer(folder_path: str, file_name: str): dfs = {} for file_name in zip_ref.namelist(): df = pd.read_csv(extracted_dir + "/" + file_name) - df_name = file_name[:-4] + file_path = Path(file_name) + df_name = file_path.stem dfs[df_name] = df visualize_vertipaq(dfs)