Skip to content

Using data getter on empty DataGrid produces key error #322

@ollyhensby

Description

@ollyhensby

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):

  • Operating System and Version: Ubuntu 20.04 WSL
  • Browser [e.g. Firefox, Safari] (if applicable): Chrome (Using Jupyter Lab)

Any help with this is much appreciated. Cheers!

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions