cftime icon indicating copy to clipboard operation
cftime copied to clipboard

Partial datetime string parsing in cftime

Open spencerahill opened this issue 7 years ago • 8 comments

Recently in the xarray mailing list (here) and in aospy (here) the need has arisen for the partial datetime string parsing that is currently implemented in xarray as private API, which we therefore don't want to rely on. @spencerkclark argued, and I think I agree, that this functionality is outside the scope of xarray in terms of making it public API.

Separately, @mcgibbon raised the notion of porting it to cftime, which I like the idea of also. Does this seem reasonable? It seems like such a common datetime-related need that it would well fit in the scope of cftime.

CC: @shoyer for any thoughts from the xarray side

spencerahill avatar Jun 01 '18 19:06 spencerahill

Yes, this definitely belong logically in cftime :)

shoyer avatar Jun 01 '18 19:06 shoyer

I think we are the only authors of this code (OK, technically Google owns what I wrote), so there should be no problem redistributing it under the cftime license.

shoyer avatar Jun 01 '18 19:06 shoyer

@spencerahill, are there any plans to submit a pull request for this?

jswhit avatar Aug 18 '18 15:08 jswhit

@jswhit I am on travel for several weeks and then under a really pressing deadline through Nov. 1, so unfortunately the earliest I would be able to get to this is sometime in November. But I'm happy to do so then. I invite someone else to do it in the meantime if there is an immediate need.

spencerahill avatar Aug 18 '18 17:08 spencerahill

OK, I will leave it open

jswhit avatar Aug 18 '18 18:08 jswhit

What would the API be for this? A cftime.strptime function, akin to datetime.strptime? The relevant code in xarray has parse_iso8601, _parse_iso8601_with_reso, and _parsed_string_to_bounds functions.

spencerahill avatar Dec 18 '18 21:12 spencerahill

Honestly it's probably fine to keep much of this in xarray. cftime.strptime feels like a nice abstraction to add here, though.

On Tue, Dec 18, 2018 at 1:13 PM Spencer Hill [email protected] wrote:

What would the API be for this? A cftime.strptime function, akin to datetime.strptime https://docs.python.org/3/library/datetime.html#datetime.datetime.strptime? The relevant code in xarray https://github.com/pydata/xarray/blob/9c8005937556211a8bf28a946744da3768846c5a/xarray/coding/cftimeindex.py#L12-L100 has parse_iso8601, _parse_iso8601_with_reso, and _parsed_string_to_bounds functions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Unidata/cftime/issues/51#issuecomment-448372480, or mute the thread https://github.com/notifications/unsubscribe-auth/ABKS1gHNj_0Rqpdkvjq7TmrgJUsq4lVAks5u6VpogaJpZM4UXM1m .

shoyer avatar Dec 18 '18 21:12 shoyer

Extending on this, we have the need to use cftime and related logic in a project (including partial strings), but we do not need any other xarray functionality. So we have been adapting some of the xarray logic for essentially dealing with cftime partial strings and offsets / timedeltas. At least within our team, we concluded it would be helpful to have some of that functionality available in cftime, for those who need to deal with these kind of dates, but do not need xarray. I'm not sure of the feeling on this - but if there was interest, we could consider directing some effort to making a PR to cftime.

swartn avatar Jun 28 '24 20:06 swartn