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

Improve date and datetime picker functionality #6152

Merged
merged 9 commits into from
Jan 10, 2024

Conversation

ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Jan 3, 2024

Some bug fixes (start/end were not applied if datetime64) and makes the following work:

Closes #6143

image
import datetime as dt
import panel as pn
import numpy as np
import xarray as xr
import hvplot.xarray

pn.extension()

ds = xr.tutorial.open_dataset("air_temperature")
viz = ds["air"].hvplot(x="lon", y="lat")
pn.panel(viz, widgets={"time": pn.widgets.DatetimePicker}).show()

panel/widgets/input.py Outdated Show resolved Hide resolved
panel/widgets/input.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 3, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (46e0639) 84.69% compared to head (7f01677) 84.70%.
Report is 8 commits behind head on main.

Files Patch % Lines
panel/widgets/input.py 87.50% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6152    +/-   ##
========================================
  Coverage   84.69%   84.70%            
========================================
  Files         296      296            
  Lines       44184    44294   +110     
========================================
+ Hits        37423    37520    +97     
- Misses       6761     6774    +13     
Flag Coverage Δ
ui-tests 40.74% <48.68%> (+<0.01%) ⬆️
unitexamples-tests 72.60% <80.26%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ahuang11 ahuang11 changed the title Improve datetime picker functionality Improve date and datetime picker functionality Jan 3, 2024
@ahuang11 ahuang11 marked this pull request as ready for review January 3, 2024 20:00
@@ -10,7 +10,7 @@ class DatetimePicker(InputWidget):

'''

value = Nullable(String, help="""
value = Nullable(Either(String, Date, Datetime), help="""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed or correct? What does bokeh convert the Date, Datetime values to?

options = list(params.pop('options'))
params['enabled_dates'] = options
if 'value' in params and hasattr(params['value'], "astype"):
value = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer not to repeat this logic multiple times. Would pull this out as a utility maybe?

@ahuang11
Copy link
Contributor Author

ahuang11 commented Jan 9, 2024

Actually I think there's an issue with the link between panel -> holoviews, and I'm not sure how to address:

image

Initially, the value is a np.datetime64

image

When a value is selected, it reverts back to datetime.datetime

image

Which I think is the root of a blank plot:

image

CC: @rsignell

@ahuang11
Copy link
Contributor Author

ahuang11 commented Jan 9, 2024

Would it be acceptable to have a as_numpy_datetime64 param?

Screen.Recording.2024-01-09.at.1.46.32.PM.mov

panel/util/__init__.py Outdated Show resolved Hide resolved
@philippjfr philippjfr merged commit bcd2a92 into main Jan 10, 2024
15 checks passed
@philippjfr philippjfr deleted the improve_datetime_picker branch January 10, 2024 14:11
@philippjfr philippjfr mentioned this pull request Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix datetimepicker for most common Pangeo xarray use case
2 participants