Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set Categorical columns containing quotes #209

Closed
althonos opened this issue Jul 9, 2018 · 1 comment
Closed

Cannot set Categorical columns containing quotes #209

althonos opened this issue Jul 9, 2018 · 1 comment

Comments

@althonos
Copy link

althonos commented Jul 9, 2018

Environment

  • Operating System: Linux
  • Python Version: 3.6.5
  • How did you install Qgrid: pip
  • Python packages:
qgrid==1.0.5
notebook==5.3.0
jupyterlab==0.32.1
  • Jupyter lab packages (if applicable): $ jupyter labextension list
@jupyter-widgets/jupyterlab-manager
        @jupyter-widgets/jupyterlab-manager v0.35.0  enabled  OK
qgrid
        qgrid v1.0.5  enabled  OK

Description of Issue

  • What did you expect to happen?

Being able to select a categorical data containing arbitrary text, including quotes. In particular, I was expecting to set a category item among `{"ConL1", "ConL2", "ConL3", "ConLS", "ConLS'"}.

  • What happened instead?
  1. When I encountered this bug for the first time, I got an error popup, and the following traceback in the server log:
[IPKernelApp] ERROR | Error occurred while attempting to edit the DataFrame. Check the notebook server logs for more information.
Traceback (most recent call last):
  File "/home/althonos/.local/lib/python3.6/site-packages/qgrid/grid.py", line 1224, in _handle_qgrid_msg_helper
    self._df.loc[location] = val_to_set
  File "/usr/lib/python3.6/site-packages/pandas/core/indexing.py", line 189, in __setitem__
    self._setitem_with_indexer(indexer, value)
  File "/usr/lib/python3.6/site-packages/pandas/core/indexing.py", line 615, in _setitem_with_indexer
    setter(item, value)
  File "/usr/lib/python3.6/site-packages/pandas/core/indexing.py", line 539, in setter
    s._data = s._data.setitem(indexer=pi, value=v)
  File "/usr/lib/python3.6/site-packages/pandas/core/internals.py", line 3693, in setitem
    return self.apply('setitem', **kwargs)
  File "/usr/lib/python3.6/site-packages/pandas/core/internals.py", line 3581, in apply
    applied = getattr(b, f)(**kwargs)
  File "/usr/lib/python3.6/site-packages/pandas/core/internals.py", line 1934, in setitem
    self.values[indexer] = value
  File "/usr/lib/python3.6/site-packages/pandas/core/arrays/categorical.py", line 1982, in __setitem__
    raise ValueError("Cannot setitem on a Categorical with a new "
ValueError: Cannot setitem on a Categorical with a new category, set the categories first
  1. When trying to come with a reproducible test case, I could only reach a point where the update would simply not happen, but no error would be raised.

Reproduction Steps

  1. Create a notebook with the following cell:
import qgrid
import pandas

df = pandas.DataFrame({'test': pandas.Categorical(['', ''], categories={'', "Hi", "'Hello'"})})
qgrid.QGridWidget(df=df, show_toolbar=True)
  1. Try to set the value of the test column to 'Hello': nothing is updated (the cell stays empty).
TimShawver pushed a commit that referenced this issue Jul 9, 2018
@TimShawver
Copy link
Contributor

Thanks for the report...this is fixed in the latest release (1.1.0) which is now available on pypi and conda.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants