Skip to content

Index overlap on multiindex with auto_fit_columns #558

@maltomato

Description

@maltomato

Summary

When I create a grid with a multiindex and apply auto_fit_columns the columns overlap. If the error occurs depends on the values. Some index value combinations lead to the issue and others do not.

To reproduce

This version creates the error:

import ipydatagrid
import numpy as np
import pandas as pd

arrays = [
    [1, 1, 1],
    [2, 2.5, 2.5],
    [999, 999, 999],
    [1000, 1000, 1000],
]
index = pd.MultiIndex.from_arrays(arrays, names=('first', 'second', 'third', 'fourth'))
columns = ['A', 'B', 'C', 'D']
df = pd.DataFrame(np.random.randn(3, 4), index=index, columns=columns)

grid = ipydatagrid.DataGrid(df, auto_fit_columns=True)
grid

image

With a slight change in the index values (changing the third 2.5 on index level 2) and it looks normal again.

import ipydatagrid
import numpy as np
import pandas as pd

arrays = [
    [1, 1, 1],
    [2, 2.5, 2],
    [999, 999, 999],
    [1000, 1000, 1000],
]
index = pd.MultiIndex.from_arrays(arrays, names=('first', 'second', 'third', 'fourth'))
columns = ['A', 'B', 'C', 'D']
df = pd.DataFrame(np.random.randn(3, 4), index=index, columns=columns)

grid = ipydatagrid.DataGrid(df, auto_fit_columns=True)
grid

image

System info

  • ipydatagrid 1.3.2
  • jupyterlab 4.2.5
  • python 3.12.5
  • ipython 8.27.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions