qgrid
qgrid copied to clipboard
Error on adding a row to an empty DataFrame
Environment
-
Operating System: Linux
-
Python Version:
$ python --versionPython 2.7.12 -
How did you install Qgrid: (
pip,conda, orother (please explain)) pip install qgrid jupyter nbextension enable --py --sys-prefix qgrid jupyter nbextension enable --py --sys-prefix widgetsnbextension -
Python packages:
$ pip freezeor$ conda list(please include qgrid, notebook, and jupyterlab versions) backports-abc==0.5 backports.shutil-get-terminal-size==1.0.0 bleach==2.1.4 configparser==3.5.0 decorator==4.3.0 defusedxml==0.5.0 entrypoints==0.2.3 enum34==1.1.6 functools32==3.2.3.post2 futures==3.2.0 html5lib==1.0.1 ipaddress==1.0.22 ipykernel==4.9.0 ipython==5.8.0 ipython-genutils==0.2.0 ipywidgets==7.4.2 Jinja2==2.10 jsonschema==2.6.0 jupyter-client==5.2.3 jupyter-core==4.4.0 MarkupSafe==1.0 mistune==0.8.3 nbconvert==5.4.0 nbformat==4.4.0 notebook==5.6.0 numpy==1.15.1 pandas==0.23.4 pandocfilters==1.4.2 pathlib2==2.3.2 pexpect==4.6.0 pickleshare==0.7.4 pkg-resources==0.0.0 prometheus-client==0.3.1 prompt-toolkit==1.0.15 ptyprocess==0.6.0 Pygments==2.2.0 python-dateutil==2.7.3 pytz==2018.5 pyzmq==17.1.2 qgrid==1.1.1 scandir==1.9.0 Send2Trash==1.5.0 simplegeneric==0.8.1 singledispatch==3.4.0.3 six==1.11.0 terminado==0.8.1 testpath==0.3.1 tornado==5.1.1 traitlets==4.3.2 wcwidth==0.1.7 webencodings==0.5.1 widgetsnbextension==3.4.2 -
Jupyter lab packages (if applicable):
$ jupyter labextension list
Description of Issue
Adding rows to the empty DataFrame does not work
- What did you expect to happen? A new cell or an error message appears
- What happened instead? 'Add Row' button stays greyed out, jupyter console reads [IPKernelApp] ERROR | max() arg is an empty sequence [IPKernelApp] ERROR | Unhandled exception while handling msg Traceback (most recent call last): File "/home/pb/play/jupyter/jupyter-venv/local/lib/python2.7/site-packages/qgrid/grid.py", line 1419, in _handle_qgrid_msg self._handle_qgrid_msg_helper(content) File "/home/pb/play/jupyter/jupyter-venv/local/lib/python2.7/site-packages/qgrid/grid.py", line 1483, in _handle_qgrid_msg_helper row_index = self._duplicate_last_row() File "/home/pb/play/jupyter/jupyter-venv/local/lib/python2.7/site-packages/qgrid/grid.py", line 1641, in _duplicate_last_row last_index = max(df.index) ValueError: max() arg is an empty sequence
Reproduction Steps
1.Create a four-cell jupyter notebook with the contents below and run it 2. 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?
...
Similar to using qgrid_widget.add_row() for an empty dataframe.
same here :(
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
@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 ;)
This issue is still present in 1.3.1