-
Notifications
You must be signed in to change notification settings - Fork 796
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
feat: Support datetime.(date|datetime)
as a SchemaBase
parameter
#3653
Conversation
The [vega-lite docs](https://vega.github.io/vega-lite/docs/datetime.html) don't mention the `utc` property - but this restricts us to `utc` or `None`
Annotation support will be complete once `mypy` starts complaining that these comments are unused
Adds two tests with "fake" utc timezones
- Tentative - Copied from `core.SelectionParameter`
The doc stated that `None` would appear after builtins, but any builtin with a length greater than 4 appeared after. The issue is not new, but became more apparent to me while writing #3653 (comment)
This was incomplete as it didn't include `None`, but was serving the same purpose as the generated alias
Added some docs to the new types, since what they describe is somewhat complex References: - https://vega.github.io/vega-lite/docs/selection.html#current-limitations - https://vega.github.io/vega-lite/docs/param-value.html - https://vega.github.io/vega-lite/docs/selection.html#project - https://github.com/vega/altair/blob/5a6f70dc193f7ed9c89e6cc22e95c9d885167939/altair/vegalite/v5/schema/vega-lite-schema.json#L23087-L23118 Resolves: - #3653 (comment) - #3653 (comment)
Need to fix this, but adding this first to demonstrate the issue. Currently the way I've typed it prevents using different types for each encoding. The goal is for each encoding to restrict types independently. E.g. here `x` is **only** `date`, `y` is **only** `float`
@dsmedia I'm hoping this PR will make it easier to resolve #3643 for you 😅 Not sure how much of the
Once this is merged I definitely want to look at how we can demonstrate this better throughout the docs. Thank you for introducing me to this rabbit hole |
Thanks! I tested this with datetime like: import datetime
dt_values = [datetime.date(2005, 1, 1), datetime.date(2009, 1, 1)] in this example: import altair as alt
from vega_datasets import data
import datetime
dt_values = [datetime.date(2005, 1, 1), datetime.date(2009, 1, 1)]
source = data.sp500.url
brush = alt.selection_interval(
encodings=["x"],
value={"x": dt_values},
mark=alt.BrushConfig(fill="#fdbb84", fillOpacity=0.5, stroke="#e34a33", strokeWidth=2),
)
base = alt.Chart(source).mark_area().encode(
x="date:T",
y="price:Q",
).properties(width=600)
upper = base.encode(
x=alt.X("date:T").scale(domain=brush)
).properties(height=200)
lower = base.encode(
).add_params(brush).properties(height=60)
upper & lower And that works good: I also tried: import polars as pl
import pandas as pd
pd_values = [pd.Timestamp('2005-01-01'), pd.Timestamp('2009-01-01')]
pl_values = [pl.date(2005, 1, 1), pl.date(2005, 1, 1)] But that didn't work. when using Error 1: '2005.dt.datetime([1, 1, 0, 0, 0, 0, String(raise)]).strict_cast(Date).alias("date")' is an invalid value for `0`. Valid values are of type 'boolean', 'number', 'string', or 'object'. I know that these might be out of scope of this PR, but just trying anyways. Btw, using the Argument of type "BrushConfig" cannot be assigned to parameter "mark" of type "Optional[Mark]" in function "selection_interval"
Type "BrushConfig" is not assignable to type "Optional[Mark]"
"BrushConfig" is not assignable to "Mark"
"BrushConfig" is not assignable to "UndefinedType" |
Thanks for trying these out @mattijn
Keeping things simple for now by only supporting It seems We can always widen the support in a follow up PR? |
Yeah I encountered that as well while working on #3544. |
Widen the support in a follow up PR sounds good. Out of curiosity: is the |
Do you mean can this be set within a theme? If so, then I would say yes if there is a |
Closes #3651
Example
This is now a working solution for #3643.
No user conversions, or dependency on
pandas
/polars
required:Code block
Screenshot
Schema output
Typing Examples
Utilizing #3656, and making some progress towards resolving #3643 - these functions now have much more useful annotations.
This wasn't straightforward to piece together, but the types (and their docs) are informed by these sources:
alt.selection_interval
2024-10-24.15-37-04.mp4
alt.selection_point
2024-10-24.15-46-02.mp4
Tasks
datetime.(date|datetime)
->core.DateTime
api.py
annotationsselection_(interval|point)
value
->core.SelectorParameter(value=...)
Mapping[SingleDefUnitChannel_T | LiteralString, Any]
_LiteralValue
alias