quantopian / qgrid

An interactive grid for sorting, filtering, and editing DataFrames in Jupyter notebooks
Apache License 2.0
3.04k stars 425 forks source link

Error on adding a row to an empty DataFrame #220

Open paulburt opened 6 years ago

paulburt commented 6 years ago

Environment

Description of Issue

Adding rows to the empty DataFrame does not work

Reproduction Steps

1.Create a four-cell jupyter notebook with the contents below and run it

  1. Press 'Add Row' button

import pandas as pd import qgrid

df = pd.DataFrame({'a':['b']}) #Add Row works

df = pd.DataFrame() #Add Row does not work qgrid.show_grid(df,show_toolbar=True)

What steps have you taken to resolve this already?

...

Anything else?

...

DancingQuanta commented 5 years ago

Similar to using qgrid_widget.add_row() for an empty dataframe.

LukaPitamic commented 5 years ago

same here :(

AlJohri commented 5 years ago

same here

[IPKernelApp] ERROR | max() arg is an empty sequence
[IPKernelApp] ERROR | Unhandled exception while handling msg
Traceback (most recent call last):
  File "/Users/johria/Development/dad-pdf-extraction/.venv/lib/python3.7/site-packages/qgrid/grid.py", line 1419, in _handle_qgrid_msg
    self._handle_qgrid_msg_helper(content)
  File "/Users/johria/Development/dad-pdf-extraction/.venv/lib/python3.7/site-packages/qgrid/grid.py", line 1483, in _handle_qgrid_msg_helper
    row_index = self._duplicate_last_row()
  File "/Users/johria/Development/dad-pdf-extraction/.venv/lib/python3.7/site-packages/qgrid/grid.py", line 1641, in _duplicate_last_row
    last_index = max(df.index)
ValueError: max() arg is an empty sequence
LukaPitamic commented 5 years ago

@AlJohri - I solved the problem by adding one dummy row to pandas data frame before QGrid gets instantiated. Also, I noticed having DateTime as Index type represents a lot of challenges to QGrid. Using "Int64" type of Index, and separate (non index) column of DateTime type solves it all in one swoop. Not ideal solution, but next best ;)

wuyuanyi135 commented 4 years ago

This issue is still present in 1.3.1