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

Localize/convert transformed_data datetimes to local_tz #208

Merged
merged 2 commits into from
Jan 2, 2023

Conversation

jonmmease
Copy link
Collaborator

Previously datetime columns returned by vf.transformed_data were naive but implicitly in the UTC timezone. This PR localizes them as UTC then converts them to VegaFusion's local timezone.

For example:

import vegafusion as vf
import altair as alt
from vega_datasets import data

# Manually set timezone to Seattle's since this a seattle weather
# dataset
vf.set_local_tz("America/Los_Angeles")

source = data.seattle_weather()

chart = alt.Chart(source).mark_bar(
    cornerRadiusTopLeft=3,
    cornerRadiusTopRight=3
).encode(
    x='month(date):O',
    y='count():Q',
    color='weather:N'
)
chart

visualization

tx_df = vf.transformed_data(chart, row_limit=5)
tx_df
weather month_date __count __count_start __count_end
0 drizzle 2012-01-01 00:00:00-08:00 10 114 124
1 rain 2012-01-01 00:00:00-08:00 35 41 76
2 sun 2012-01-01 00:00:00-08:00 33 0 33
3 snow 2012-01-01 00:00:00-08:00 8 33 41
4 rain 2012-02-01 00:00:00-08:00 40 33 73
tx_df.dtypes
weather                                       object
month_date       datetime64[ns, America/Los_Angeles]
__count                                        int64
__count_start                                  int64
__count_end                                    int64
dtype: object

@jonmmease jonmmease merged commit bd94aec into main Jan 2, 2023
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.

1 participant