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

provide tzinfo attribute on cftime.datetime objects #208

Closed
rabernat opened this issue Nov 13, 2020 · 4 comments
Closed

provide tzinfo attribute on cftime.datetime objects #208

rabernat opened this issue Nov 13, 2020 · 4 comments

Comments

@rabernat
Copy link

Cftime datetimes are mostly duck-compatible with standard python datetimes. However, they lack the tzinfo attribute.

import datetime
d = datetime.datetime(2000, 1, 1)
assert d.tzinfo is None

import cftime
c = cftime.datetime(2000, 1, 1)
assert c.tzinfo is None
# -> AttributeError: 'cftime._cftime.datetime' object has no attribute 'tzinfo'

This caused a bug recently in pystack: stac-utils/pystac#238. I notice it also caused an internal bug in cftime (#126), which was fixed with #127 by replacing a reference to .tzinfo with a getattr call (similar to my workaround in stac-utils/pystac#238).

Rather than patching all the downstream libraries that might want to work with cftime datetimes (which might not realize they are not regular datetimes) to avoid assuming this attribute exist, wouldn't it be easier to provide a .tzinfo attribute on cftime dates?

Thanks for considering my suggestion.

@jswhit
Copy link
Collaborator

jswhit commented Nov 13, 2020

What do you suggest? cftime.datetime.tzinfo = None?

@rabernat
Copy link
Author

Yes that would be consistent with datetime.

jswhit added a commit that referenced this issue Nov 15, 2020
add datetime.tzinfo=None (closes issue #208)
@jswhit
Copy link
Collaborator

jswhit commented Nov 15, 2020

closed by PR #209

@jswhit jswhit closed this as completed Nov 15, 2020
@rabernat
Copy link
Author

Thank you so much!

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