Skip to content

Commit

Permalink
More robustness when dealing with pandas column multi-index. Cleaner.
Browse files Browse the repository at this point in the history
  • Loading branch information
yohplala committed Aug 21, 2024
1 parent 02228b1 commit 742c2e7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions oups/store/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ def check_cmidx(chunk):
None
"""
# If a name is 'None', set it to '' instead.
cmidx = chunk.columns
for i, name in enumerate(cmidx.names):
if name is None:
cmidx.set_names("", level=i, inplace=True)
# If an item of the column name is not a string, turn it into a string.
# Using 'set_levels()' instead of rconstructing a MultiIndex to preserve
# index names directly.
Expand All @@ -256,11 +260,6 @@ def check_cmidx(chunk):
level_updated.append(str_level)
if level_updated:
chunk.columns = chunk.columns.set_levels(level_updated, level=level_updated_idx)
# If a name is 'None', set it to '' instead.
cmidx = chunk.columns
for i, name in enumerate(cmidx.names):
if name is None:
cmidx.set_names("", level=i, inplace=True)


def write_metadata(
Expand Down

0 comments on commit 742c2e7

Please sign in to comment.