altair icon indicating copy to clipboard operation
altair copied to clipboard

Wide support for `datetime.(date|datetime)`

Open dangotbanned opened this issue 1 year ago • 1 comments

What is your suggestion?

While I was writing https://github.com/vega/altair/issues/3643#issuecomment-2425132002, I was unsatisfied with how a user would need to handle stdlib types.

For example, these two are functionally equivalent:

from datetime import date, datetime

import altair as alt

window_stdlib = (
    datetime(2005, 1, 1).timestamp() * 1e3,
    datetime(2009, 1, 1).timestamp() * 1e3,
)
window_alt = alt.DateTime(year=2005), alt.DateTime(year=2009)

brush = alt.selection_interval(encodings=["x"], value={"x": window_stdlib})
brush = alt.selection_interval(encodings=["x"], value={"x": window_alt})

The need to convert from a format python understands, to one which javascript expects; really seems like a detail that altair should be handling.

Sub Issues

I've opened sub-issues, with this as a parent.

I had already implemented some level of support for these locally, but beyond the shared topic - they touch completely different areas of altair. For that reason, I'm going to track in smaller individual PRs.

The end goal will be supporting datetime.(date|datetime) in the same way (int|float|bool|str) can be used (schema permitting)

  • [x] #3651
  • [ ] #3652

Related

  • #3643
    • Inspiration for this new functionality
  • #2199
    • Dealing with a pd.Series[datetime.date] within alt.Chart.data
    • This issue is not focused on this case

Have you considered any alternative solutions?

No response

dangotbanned avatar Oct 22 '24 10:10 dangotbanned

The need to convert from a format python understands, to one which javascript expects; really seems like a detail that altair should be handling.

I totally agree, thanks for working on this @dangotbanned!

joelostblom avatar Oct 23 '24 01:10 joelostblom