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

Add DateRangePicker #5844

Closed
MarcSkovMadsen opened this issue Nov 10, 2023 · 3 comments · Fixed by #6027
Closed

Add DateRangePicker #5844

MarcSkovMadsen opened this issue Nov 10, 2023 · 3 comments · Fixed by #6027
Labels
type: enhancement Minor feature or improvement to an existing feature
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

Panel has a DatetimeRangePicker. But not DataRangePicker.

I need it to work with param.CalenderDate parameters.

I cannot use the DatetimeRangePicker because 1) the formatting will always show time (format parameter not supported) and 2) the widget will return datetime tuples. Not date tuples.

import panel as pn
import param
from datetime import date

class Model(param.Parameterized):
    period = param.CalendarDateRange(default=(date(2022,1,1), date(2022,1,3)), bounds=(date(2022,1,1), date(2022,1,5)))

model = Model()

widget = pn.widgets.DatetimeRangePicker.from_param(model.param.period, enable_time=False)

def out(value):
    return str(value)

pn.Column(
    widget, pn.bind(out, model.param.period)
).servable()

When I change the selection I get.

 File "/home/jovyan/repos/private/panel/panel/param.py", line 513, in link_widget
    self.object.param.update(**{p_name: change.new})
  File "/home/jovyan/repos/private/panel/.venv/lib/python3.10/site-packages/param/parameterized.py", line 2282, in update
    restore = self_._update(*args, **kwargs)
  File "/home/jovyan/repos/private/panel/.venv/lib/python3.10/site-packages/param/parameterized.py", line 2315, in _update
    setattr(self_or_cls, k, v)
  File "/home/jovyan/repos/private/panel/.venv/lib/python3.10/site-packages/param/parameterized.py", line 525, in _f
    instance_param.__set__(obj, val)
  File "/home/jovyan/repos/private/panel/.venv/lib/python3.10/site-packages/param/parameterized.py", line 527, in _f
    return f(self, obj, val)
  File "/home/jovyan/repos/private/panel/.venv/lib/python3.10/site-packages/param/parameterized.py", line 1490, in __set__
    self._validate(val)
  File "/home/jovyan/repos/private/panel/.venv/lib/python3.10/site-packages/param/parameters.py", line 1274, in _validate
    self._validate_bounds(val, self.bounds, self.inclusive_bounds, 'bound')
  File "/home/jovyan/repos/private/panel/.venv/lib/python3.10/site-packages/param/parameters.py", line 1330, in _validate_bounds
    too_low = (vmin is not None) and (v < vmin if incmin else v <= vmin)
TypeError: can't compare datetime.datetime to datetime.date

There is an old, open PR to implement this in #2804

@MarcSkovMadsen MarcSkovMadsen added the type: enhancement Minor feature or improvement to an existing feature label Nov 10, 2023
@MarcSkovMadsen MarcSkovMadsen added this to the Wishlist milestone Nov 10, 2023
@MarcSkovMadsen MarcSkovMadsen changed the title Add DataRangePicker Add DateRangePicker Nov 10, 2023
@TheoMathurin
Copy link
Contributor

TheoMathurin commented Dec 8, 2023

I also need this widget in multiple apps.

Now that it's implemented in bokeh I think there's a pretty straightforward process to include it in Panel but I don't have the details. I'm willing to do it if I have the necessary info.

@TheoMathurin
Copy link
Contributor

In fact it seems like we're waiting for something to be fixed upstream. See #3789 (comment)

@hoxbro
Copy link
Member

hoxbro commented Dec 8, 2023

I don't think DateRangePicker is affected by the problem; only Datetime pickers are.

You should be able to add something like this to Panel by copying DatePicker, and replacing the _widget_type with DateRangePicker. Could be the case that you will need to update the msg in self._process_property_change and _process_param_change.

class DatePicker(Widget):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants