jupyter-widgets / ipydatagrid

Fast Datagrid widget for the Jupyter Notebook and JupyterLab
BSD 3-Clause "New" or "Revised" License
580 stars 51 forks source link

Using data getter on empty DataGrid produces key error #322

Closed ollyhensby closed 2 years ago

ollyhensby commented 2 years ago

Describe the bug When there's no data in the grid, the data getter produces an error.

To Reproduce Steps to reproduce the behavior:

  1. Import DataGrid and pandas
from ipydatagrid import DataGrid
import pandas as pd
  1. Create simple dataframe and input into DataGrid
df = pd.DataFrame([1], columns=["a"])
grid = DataGrid(df)
grid

We get this output: image

We can also call the data getter:

grid.data

image

  1. Now drop all the rows in the dataframe and set using the data setter.
grid.data = grid.data.drop(0)

We see that the DataGrid UI object reflects those changes (we only have the columns):

image

  1. Now call the data getter:
grid.data
  1. See error

image

Expected behavior I expect an empty dataframe to be returned like this when calling the data getter:

image

Environment (please complete the following information):

Any help with this is much appreciated. Cheers!

ibdafna commented 2 years ago

Hello :wave: @ollyhensby and welcome to the ipydatagrid community! Many thanks for reporting - I'll get this fixed!

ibdafna commented 2 years ago

Closed via #358 Awesome work @ollyhensby 🙏 Thank you!