From 4d0838988100ab43b81a1a648ed892c4256942fd Mon Sep 17 00:00:00 2001 From: HowToSD Date: Fri, 21 Feb 2025 13:07:42 -0800 Subject: [PATCH] Fixed Pandas Loc Row MultiIndex DataFrame to handle a case where only the first index is specified when the DataFrame has MultiIndex. --- .../pandas_loc_row_multiindex_dataframe.py | 12 ++++++++---- pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/pandas_wrapper/pandas_loc_row_multiindex_dataframe.py b/modules/pandas_wrapper/pandas_loc_row_multiindex_dataframe.py index 516e67f..c2b56fa 100644 --- a/modules/pandas_wrapper/pandas_loc_row_multiindex_dataframe.py +++ b/modules/pandas_wrapper/pandas_loc_row_multiindex_dataframe.py @@ -58,10 +58,14 @@ class PandasLocRowMultiIndexDataFrame: # This will throw an exception if the MultiIndex is not an int. if row_index_type == "int": ind_list = [int(ind) for ind in ind_list] - - ind_tuple = tuple(ind_list) + + ind_tuple = tuple(ind_list) # Convert the list to a tuple + if len(ind_tuple) == 1: # Do not enclose in tuple if only 1 index is specified + ind = ind_tuple[0] + else: + ind = ind_tuple # We need to wrap it to get the DataFrame. Otherwise, we will get a Series. - ind_tuple_list = [ind_tuple] - value = dataframe.loc[ind_tuple_list] + ind_list = [ind] + value = dataframe.loc[ind_list] return (value,) diff --git a/pyproject.toml b/pyproject.toml index 1614496..5df23da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "data-analysis" description = "Data analysis custom modules for ComfyUI - Use Pandas & Matplotlib within ComfyUI" -version = "1.1.16" +version = "1.1.17" license = {file = "LICENSE"} [project.urls]