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

Issue with TimeZone conversion #9

Closed
mbataillou opened this issue Sep 2, 2023 · 2 comments
Closed

Issue with TimeZone conversion #9

mbataillou opened this issue Sep 2, 2023 · 2 comments

Comments

@mbataillou
Copy link

Hello!

When adding a timezone to a DateTime column using the tz string macro it fails with error UndefVarError: @tz_str not defined.

using Tidier, Dates, TimeZones, DataFrames
df = DataFrame(dt=mdy_hms("9/22/2023 18:45:00"))

# This fails
@chain df begin
	@mutate(dt_tz=ZonedDateTime(dt, tz"UTC"))
end

# This works
@chain df begin
        @mutate(dt_tz=ZonedDateTime(dt, Dates.TimeZone("UTC")))
end

If one uses DataFramesMeta it works with the @rtransform:

# This works
@chain df begin
        @rtransform(:dt_tz=ZonedDateTime(:dt, tz"UTC"))
end

Thanks for the great work :)

@drizk1
Copy link
Member

drizk1 commented Sep 2, 2023

I'm happy you enjoy the work.

I have a feeling the error may be due to how macros are expanded in side of the mutate() macro. I am not entirely sure the best approach to fix this, but in the mean time another workaround that would mitigate the need to call the full function would be as follows

mytz() = tz"UTC"
@chain df begin
    @mutate(dt_tz=ZonedDateTime(dt, mytz()))
end

@drizk1
Copy link
Member

drizk1 commented Dec 17, 2023

The below now works with updates to how @Mutate interacts with macros within it now in the most recent TidierData.jl, so I will close the issue

@chain df begin
	@mutate(dt_tz=ZonedDateTime(dt, tz"UTC"))
end

@drizk1 drizk1 closed this as completed Dec 17, 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

No branches or pull requests

2 participants