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