| 355 | |
| 356 | |
| 357 | def guarantee_multiindex_rows(df): |
| 358 | # Make paths platform-agnostic if they are not already |
| 359 | if not isinstance(df.index, pd.MultiIndex): # Backwards compatibility |
| 360 | path = df.index[0] |
| 361 | try: |
| 362 | sep = "/" if "/" in path else "\\" |
| 363 | splits = tuple(df.index.str.split(sep)) |
| 364 | df.index = pd.MultiIndex.from_tuples(splits) |
| 365 | except TypeError: # Ignore numerical index of frame indices |
| 366 | pass |
| 367 | |
| 368 | # Ensure folder names are strings |
| 369 | try: |
| 370 | df.index = df.index.set_levels(df.index.levels[1].astype(str), level=1) |
| 371 | except AttributeError: |
| 372 | pass |
| 373 | |
| 374 | |
| 375 | def robust_split_path(s): |