Tabulator inability to "clear" columns

Hi,

We have an app that uses a Tabulator component to allow the user to edit a pandas DataFrame.
One of the columns in the table is an override value (float with a NumberEditor), that if set, is used instead of a calculated value in further calculations (e.g. manual_override set → use that instead of calculated_value).
Since it’s an override, it needs to be able to be disabled again.

When we try and clear the field and hence get it set back to NaN, we get the following error:

2022-08-22 15:55:06,151 - bokeh.server.protocol_handler - ERROR - error handling message
 message: Message 'PATCH-DOC' content: {'events': [{'kind': 'ColumnsPatched', 'column_source': {'id': '26128'}, 'patches': {'override_column': [[0, '']]}}], 'references': []}
 error: ValueError("could not convert string to float: ''")
Traceback (most recent call last):
  File "C:\app\lib\site-packages\bokeh\server\protocol_handler.py", line 97, in handle
    work = await handler(message, connection)
  File "C:\app\lib\site-packages\bokeh\server\session.py", line 95, in _needs_document_lock_wrapper
    result = func(self, *args, **kwargs)
  File "C:\app\lib\site-packages\bokeh\server\session.py", line 289, in _handle_patch
    message.apply_to_document(self.document, self)
  File "C:\app\lib\site-packages\bokeh\protocol\messages\patch_doc.py", line 115, in apply_to_document
    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.content, setter))
  File "C:\app\lib\site-packages\bokeh\document\callbacks.py", line 408, in invoke_with_curdoc
    return f()
  File "C:\app\lib\site-packages\bokeh\protocol\messages\patch_doc.py", line 115, in <lambda>
    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.content, setter))
  File "C:\app\lib\site-packages\bokeh\document\document.py", line 391, in apply_json_patch
    DocumentPatchedEvent.handle_json(self, event_json, references, setter)
  File "C:\app\lib\site-packages\bokeh\document\events.py", line 259, in handle_json
    handler(doc, event_json, references, setter)
  File "C:\app\lib\site-packages\bokeh\document\events.py", line 767, in _handle_json
    source.patch(patches, setter)
  File "C:\app\lib\site-packages\bokeh\models\sources.py", line 721, in patch
    self.data._patch(self.document, self, patches, setter)
  File "C:\app\lib\site-packages\bokeh\core\property\wrappers.py", line 482, in _patch
    self[name][ind] = value
ValueError: could not convert string to float: ''

I’m honestly not entirely sure whether this is a Panel, Bokeh or tabulator issue, and I am aware that there are some known issues wrt. dealing with NaN values in tabulator/panel/pandas.

Any suggestions on how to fix or workaround? Is it actually a supported use-case?

A quickhack that makes it work is explicitly converting '' to to NaN in PropertyValueColumnData (bokeh/core/property/wrappers.py) if we are dealing with a float and the incoming value is '', but it feels somewhat malplaced to patch it in bokeh (I would possibly expect it to maybe be handled in the panel tabulator javascript hooks?)

It is probably a bug, but without a minimal, reproducible example (MRE) it is hard to verify it.

Of course :slight_smile: I just wanted to verify whether it was expected behaviour or not first :slight_smile:

My user is too new to upload attachments so I’ll put the code inline here.
Repro steps:

  1. Run app with panel serve filename.py
  2. Visit app :wink:
  3. Edit col2 in any row and delete the contents and leave column/press enter
  4. Observe Error in log and that visually, the value is set to “0.0”

Note that the 5th item that starts as NaN is correctly shown as - but the second you enter that column and try to leave it without entering a value, the same error happens too.

Relevant versions:
panel==0.13.1
pandas==1.4.2
bokeh==2.4.3

import numpy as np
import pandas as pd
import panel as pn

pn.extension("tabulator", sizing_mode="stretch_width")


app = pn.template.BootstrapTemplate(title="Tabulator test")

data = pd.DataFrame(data={"col2": [1.1, 1.2, 1.3, 1.4, np.NaN]})

tab = pn.widgets.Tabulator(
    data,
)
app.main.append(pn.Row(tab))

if __name__.startswith("bokeh_app"):
    app.servable()

Definitely a bug can you post a bug on Github?

Done: Unable to clear float columns in Tabulator · Issue #3774 · holoviz/panel (github.com)

1 Like