Skip to content

"TypeError: data is already tz-aware UTC" in get_calendar() #45

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

Closed
acowlikeobject opened this issue Jan 31, 2019 · 1 comment · Fixed by #48
Closed

"TypeError: data is already tz-aware UTC" in get_calendar() #45

acowlikeobject opened this issue Jan 31, 2019 · 1 comment · Fixed by #48

Comments

@acowlikeobject
Copy link

from trading_calendars import get_calendar
get_calendar('CME')

Raises TypeError: data is already tz-aware UTC, unable to set specified tz: UTC.

This is a result of this issue in pandas where 'UTC' and pytz.UTC are not considered equal (I'm seeing this in pandas version 0.24.0).

I believe the fix would be to change the return in trading_calendars.trading_calendar.scheduled_special_times():

return pd.Series(
        index=pd.DatetimeIndex(days, tz='UTC'),
        data=days_at_time(days, time, tz=tz),
)

to:

return pd.Series(
        index=pd.DatetimeIndex(days, tz=pytz.UTC),
        data=days_at_time(days, time, tz=tz),
)

(Basically, replace 'UTC' with pytz.UTC when creating the index.)

@acowlikeobject
Copy link
Author

acowlikeobject commented Jan 31, 2019

For now, monkey patching works:

import pytz
import trading_calendars as tc

def scheduled_special_times(calendar, start, end, time, tz):
    days = calendar.holidays(start, end)
    return pd.Series(
        index=pd.DatetimeIndex(days, tz=pytz.UTC),
        data=tc.trading_calendar.days_at_time(days, time, tz=tz),
)
tc.trading_calendar.scheduled_special_times = scheduled_special_times
tc.get_calendar('CME')

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 a pull request may close this issue.

1 participant