Skip to content

Proposed API change: netcdftime.datetime should be immutable #255

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
shoyer opened this issue May 9, 2014 · 4 comments
Closed

Proposed API change: netcdftime.datetime should be immutable #255

shoyer opened this issue May 9, 2014 · 4 comments

Comments

@shoyer
Copy link
Contributor

shoyer commented May 9, 2014

If we make netcdftime.datetime immutable, we can define a __hash__ method and thus use these objects as a dictionary keys. Note that python's standard library datetime.datetime object is immutable for precisely this reason.

Why is this useful? In xray, we use netCDF4 to decode dates with non-standard calendars, and (currently) store the results as an array of netcdftime.datetime objects. If these objects were hashable, it would be possible to use datetime objects to perform fast location based lookups (using a hash table) along a time dimension labeled by these phony datetime objects.

I doubt that this will break anyone's code, since it would be weird to mutate a datetime object in-place, but since this would change the existing API I thought it would be worth discussing before filing a pull request. At the very least, I think mutating a datetime object should be deprecated, so that it is possible change this behavior in a future release.

@jswhit
Copy link
Collaborator

jswhit commented May 9, 2014

Sounds reasonable to me.

@jswhit
Copy link
Collaborator

jswhit commented May 14, 2014

Is a pull request coming?

@shoyer
Copy link
Contributor Author

shoyer commented May 14, 2014

Yes, when I have the time to get it together :).

On Wed, May 14, 2014 at 12:48 PM, Jeff Whitaker [email protected]
wrote:

Is a pull request coming?

Reply to this email directly or view it on GitHub:
#255 (comment)

@jswhit
Copy link
Collaborator

jswhit commented May 14, 2014

No problem, just checking..

ddasilva pushed a commit to ddasilva/netcdf4-python that referenced this issue Jul 4, 2014
ddasilva pushed a commit to ddasilva/netcdf4-python that referenced this issue Jul 4, 2014
ddasilva pushed a commit to ddasilva/netcdf4-python that referenced this issue Jul 4, 2014
ddasilva pushed a commit to ddasilva/netcdf4-python that referenced this issue Jul 4, 2014
@jswhit jswhit closed this as completed in d7aad0f Jul 8, 2014
jswhit added a commit that referenced this issue Jul 8, 2014
Make netcdftime.datetime immutable and hashable. Fixes #255.
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