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

Expose Timezone._utcoffset property for pandas compatibility #485

Closed
wants to merge 3 commits into from

Conversation

ddelange
Copy link

@ddelange ddelange commented Jul 16, 2020

This commit allows pandas to get _utcoffset from a Timezone object, taking the transision as seen from utcnow.

As explained by @sdispater in the issues linked below, pandas tries to access the Timezone._utcoffset property (which isn't currently implemented for variable Timezone objects) and subsequently tries to get Timezone.utcoffset(None) (which correctly returns None as it can't be determined without knowlede of date and time). This PR allows pandas to treat Timezones as if they were FixedTimezones (as returned for utcnow).

ref:
https://github.com/pandas-dev/pandas/blob/v1.0.5/pandas/_libs/tslibs/timezones.pyx#L152

Fixes pandas-dev/pandas#15986
Closes #131

>>> import pendulum
>>> import pandas
>>> pandas.date_range(start=pendulum.yesterday(), end=pendulum.tomorrow())
DatetimeIndex(['2020-07-15 00:00:00+02:00', '2020-07-16 00:00:00+02:00',
               '2020-07-17 00:00:00+02:00'],
              dtype='datetime64[ns, Timezone('Europe/Berlin')]', freq='D')

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

Left this unticked, as it's a private property that users won't touch.

ddelange added 2 commits July 16, 2020 13:42
Fixes pandas-dev/pandas#15986
Closes python-pendulum#131

As explained by @sdispater in the issues above, pandas tries to access the Timezone._utcoffset property: https://github.com/pandas-dev/pandas/blob/v1.0.5/pandas/_libs/tslibs/timezones.pyx#L153

This commit allows pandas to get _utcoffset from a Timezone object, taking the transision as seen from utcnow.
@ddelange ddelange changed the title Patch 1 Expose Timezone._utcoffset property for pandas compatibility Jul 16, 2020
@ddelange
Copy link
Author

ddelange commented Sep 2, 2020

Closing this as it's quite incorrect behaviour

@ddelange ddelange closed this Sep 2, 2020
@philsheard
Copy link

It doesn't appear that this has been addressed on either library, so if anyone wants a workaround then this worked for me:

Do a roundtrip from Pendulum > ISO format > Pandas to avoid the internal lookup that causes the warning.

converted_date = pandas.to_datetime(pendulum.today().isoformat())

Not pretty but it will clean your error logs without hurting comprehension.

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.

Pandas compatibility of Timezone / Timezone Info ENH: support pendulum objects
2 participants