Why does DateRangeSlider throw a TypeError when used as a Tabulator filter?

Hi,

I am trying to use a DateRangeSlider widget as a filter on a Tabulator table. The table is populated from a pandas DataFrame. I am trying to filter on a specific column that has dtype datetime64[ns].

When I change the value of the DateRangeSlider on my dashboard I get an error saying:

TypeError: ‘>=’ not supported between instances of ‘float’ and ‘datetime.datetime’

Here is how I am setting up the filter:

date_range_slider = pn.widgets.DateRangeSlider(
	name=f"Filter by date range",
	start=datetime(2021, 9, 1),
	end=datetime(2021, 10, 1),
	value=(start, end),
)
tabulator.add_filter(date_range_slider, "date")

Why am I getting this error? How can I fix my code?

Thanks,
urig

Below is the full traceback for my error:

2021-10-17 17:53:44,188 Exception in callback functools.partial(<bound method IOLoop._discard_future_result of <tornado.platform.asyncio.AsyncIOMainLoop object at 0x0000021F52263B20>>, <Ta
sk finished name='Task-3831' coro=<_needs_document_lock.<locals>._needs_document_lock_wrapper() done, defined at C:\dev\github\urig\entropy\.venv\lib\site-packages\bokeh\server\session.py:
51> exception=TypeError("'>=' not supported between instances of 'float' and 'datetime.datetime'")>)
Traceback (most recent call last):
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\tornado\ioloop.py", line 741, in _run_callback
    ret = callback()
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\tornado\ioloop.py", line 765, in _discard_future_result
    future.result()
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\bokeh\server\session.py", line 71, in _needs_document_lock_wrapper
    result = await result
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\tornado\gen.py", line 216, in wrapper
    result = ctx_run(func, *args, **kwargs)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\panel\reactive.py", line 252, in _change_coroutine
    self._change_event(doc)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\panel\reactive.py", line 262, in _change_event
    self._process_events(events)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\panel\reactive.py", line 245, in _process_events
    self.param.set_param(**self._process_property_change(events))
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\param\parameterized.py", line 1526, in set_param
    self_._batch_call_watchers()
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\param\parameterized.py", line 1665, in _batch_call_watchers
    self_._execute_watcher(watcher, events)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\param\parameterized.py", line 1627, in _execute_watcher
    watcher.fn(*args, **kwargs)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\panel\widgets\tables.py", line 875, in _update_cds
    super()._update_cds(*events)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\panel\util.py", line 370, in wrapped
    fn(self, *args, **kwargs)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\panel\reactive.py", line 652, in _update_cds
    self._processed, self._data = self._get_data()
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\panel\widgets\tables.py", line 793, in _get_data
    df = self._filter_dataframe(self.value)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\panel\widgets\tables.py", line 228, in _filter_dataframe
    mask = (column>=start) & (column<=end)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\pandas\core\ops\common.py", line 69, in new_method
    return method(self, other)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\pandas\core\arraylike.py", line 52, in __ge__
    return self._cmp_method(other, operator.ge)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\pandas\core\series.py", line 5502, in _cmp_method
    res_values = ops.comparison_op(lvalues, rvalues, op)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\pandas\core\ops\array_ops.py", line 284, in comparison_op
    res_values = comp_method_OBJECT_ARRAY(op, lvalues, rvalues)
  File "C:\dev\github\urig\entropy\.venv\lib\site-packages\pandas\core\ops\array_ops.py", line 73, in comp_method_OBJECT_ARRAY
    result = libops.scalar_compare(x.ravel(), y, op)
  File "pandas\_libs\ops.pyx", line 107, in pandas._libs.ops.scalar_compare
TypeError: '>=' not supported between instances of 'float' and 'datetime.datetime'

Could you provide a full example with some sample data? Can’t reproduce using the simple example I tried.

Thanks Phillip.

My version of Panel is:

name         : panel
version      : 0.12.4
description  : A high level app and dashboarding solution for Python.

dependencies
 - bleach *
 - bokeh >=2.4.0,<2.5.0
 - markdown *
 - param >=1.10.0
 - pyct >=0.4.4
 - pyviz-comms >=0.7.4
 - requests *
 - tqdm >=4.48.0

Code that reproduces the problem:

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

pn.extension("tabulator")

dates = pd.date_range(
    start=np.datetime64("2021-09-01"), end=np.datetime64("2021-10-30")
)
df = pd.DataFrame(dates)

table = pn.widgets.Tabulator(
    df,
    name="Dates",
    disabled=True,
    show_index=False,
)

start = np.datetime64("2021-09-01")
end = np.datetime64("2021-10-30")
date_range_slider = pn.widgets.DateRangeSlider(
    name=f"Filter by dates",
    start=start,
    end=end,
    value=(start, end),
)

table.add_filter(date_range_slider, 0)

row = pn.Row(table, pn.Spacer(width=300), date_range_slider, width=1000)
row.servable()

PS - Unrelated but strange: If I remove the Spacer in the middle of the row, the DateRangeSlider overlaps the Tabulator. Does the same thing happen to you?