Meta-issue on date filters/widgets across Lumen, Panel and Param
This is a meta-issue on the handling of datetime widgets across Lumen, Panel and Param. I'm posting it here as the goal of this analysis was to see what were the missing parts to update the date/datetime filters offered by Lumen. But of course this entails improving Panel, and in some cases improving Param (as was done recently with improving the serialization support, to allow syncing a date filter value with the URL).
For now, this skips mentioning time zones, which is another analysis of its own.
Python
First useful observation, datetime.datetime is a subclass of datetime.date.
Param 1.12.2
Date Parameters and the types they accept
Given the type alias dt_types as datetime.date | datetime.datetime | np.datetime64.
-
CalendarDate:
datetime.dateand notdatetime.datetime -
Date:
dt_types -
CalendarDateRange:
Tuple[datetime.date, datetime.date] -
DateRange:
Tuple[dt_types, dt_types]
Observations/Suggestions
CalendarDateRange actually accepts a tuple that contain one or more datetime.datetime values. Not sure how disruptive it would be to change that.
Panel 0.13.1
Date Widgets
| Panel Widget | value Param | Display as |
|---|---|---|
| DatePicker | CalendarDate | calendar date |
| DatetimePicker | Date | datetime |
| DatetimeRangePicker | DateRange | datetime |
| DateSlider | Date | calendar date |
| DateRangeSlider | DateRange | calendar date |
| DatetimeRangeSlider | DateRange | datetime |
| DatetimeInput | Date | datetime |
| DatetimeRangeInput | Tuple | datetime |
Observations/Suggestions
-
DatetimeRangeSlideris new and inherits all fromDateRangeSliderexcept that it is based on another Bokeh widget that renders the values as datetimes.DateRangeSlider'svalueParameter should beCalendarDate -
DateSliderhas aas_datetimeBoolean Parameter that whenTrueleas tovaluebeing casted todatetime.dateordatetime.datetime. - Missing
DatetimeSliderwhose display is a datetime:- See https://github.com/holoviz/panel/issues/1972 asking for it and asking for providing base widgets with a
typeargument. - See https://github.com/holoviz/panel/issues/2731 by Marc asking for it too.
- See https://github.com/holoviz/panel/issues/1972 asking for it and asking for providing base widgets with a
- Missing
DateRangePickerwhosevalueParameter is aCalendarDateRange. There's actually an open PR by a contributor: https://github.com/holoviz/panel/pull/2804 - Missing a
DateInputwidget whosevalueParameter is aCalendarDateand displays as a calendar date -
DatetimeRangeInputwon't serialize as the Parameter that holds the datetime values isn't a date-like Parameter but a bare tuple.
Lumen
Current Date Filters
Lumen currently has one date filter -DateFilter - whose behavior can be changed by setting the mode parameter:
-
slider:DateRangeSlider -
picker:DatePicker
Observations/Suggestions
- More date filters should be made available to Lumen users!
- Add datetime filters as there's currently none.
-
WidgetFilterandBinFilterboth have amultiparameter,multi=Truemeaning that a multi-select widget is used instead of a single-select widget. As far as possible this distinction should be reused to keep the
Suggested changes to DateFilter:
Mostly by adding a multi parameter that is True by default asmulti is True by default for WidgetFilter and BinFilter. mode being currently 'slider' by default this also preserves the current default widget users get by declaring a DateFilter. However, when mode is set to 'picker' the proposed logic would lead to a DateRangePicker, that doesn't yet exist. There are three options:
- add the
DateRangePickerto Panel before its next release and the next release of Lumen - temporarily return a
DatetimeRangePicker, and make sure that the date types are correctly handled - temporarily return anyway a
DatePicker, to totally preserve backwards compatibility, raising a warning that this should change in a future version in favor of aDateRangePicker. We may have to bend the code in a weird way for this to work, as aDatePickerisn't a multi type of widget
I'd go for 1, or 2, but not 3 as I've got access to a code base with many Lumen apps where I saw no usage at all of the 'picker' mode.
| multi | mode | Panel widget |
|---|---|---|
| True | slider | DateRangeSlider |
| True | picker | 1, 2 or 3? |
| False | slider | DateSlider |
| False | picker | DatePicker |
Suggesting adding a new DatetimeFilter:
| multi | mode | Panel widget |
|---|---|---|
| True | slider | DatetimeRangeSlider |
| True | picker | DatetimeRangePicker |
| False | slider | fallback to DatetimePicker |
| False | picker | DatetimePicker |
As there's no DatetimeSlider I would just document that this isn't yet a supported case, emit a warning and fall back to a DatetimePicker.