Skip to content

Commit 9eaac4d

Browse files
committed
🐛 Fix adding index columns as columns for MultiIndexes
1 parent 18ad4fc commit 9eaac4d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/mods4pandas/lib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,12 @@ def insert_into_db_multiple(con, table, ld: List[Dict]):
423423
def convert_db_to_parquet(con, table, index_col, output_file):
424424
df = pd.read_sql_query(f"SELECT * FROM {table}", con, index_col)
425425

426-
# Add index column as regular column, too
427-
df[index_col] = df.index
426+
# Add index column(s) as regular column(s), too
427+
if isinstance(df.index, pd.MultiIndex):
428+
for ic in index_col:
429+
df[ic] = df.index.get_level_values(ic)
430+
else:
431+
df[index_col] = df.index
428432

429433
# Convert Python column type into Pandas type
430434
for c in df.columns:

0 commit comments

Comments
 (0)