From 9eaac4d86da456e9e69c1c38be67711914731d4a Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Tue, 19 Aug 2025 19:30:01 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20adding=20index=20columns?= =?UTF-8?q?=20as=20columns=20for=20MultiIndexes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mods4pandas/lib.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mods4pandas/lib.py b/src/mods4pandas/lib.py index 96644ed..082a7ef 100644 --- a/src/mods4pandas/lib.py +++ b/src/mods4pandas/lib.py @@ -423,8 +423,12 @@ def insert_into_db_multiple(con, table, ld: List[Dict]): def convert_db_to_parquet(con, table, index_col, output_file): df = pd.read_sql_query(f"SELECT * FROM {table}", con, index_col) - # Add index column as regular column, too - df[index_col] = df.index + # Add index column(s) as regular column(s), too + if isinstance(df.index, pd.MultiIndex): + for ic in index_col: + df[ic] = df.index.get_level_values(ic) + else: + df[index_col] = df.index # Convert Python column type into Pandas type for c in df.columns: