-
Notifications
You must be signed in to change notification settings - Fork 286
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 a neat way to get date strings from arrays with date units. #4508
Comments
I wanted this again today. I think the implementation is easy, and the hard bit is deciding what the interface should be. So marking this for discussion. |
One option which seemed favourable in peloton discussions: adding a Actual implementation might look something like def __format__(self, fmt):
return str([format(point, fmt) for point in self.units.num2date(self.points)]) Just needs a bit more thought into points vs bounds (always both? extra symbol in the fmt string to choose one or the other?) |
As one immediately upvoting this feature I am really looking forward to this, and I would very much favour the possibility to choose only points, only bounds, or both. Many thanks /L |
I wanted this again today so I rolled my own def print_coord_times(coord, points=True, bounds=True):
"""
Given a time type coordinate (e.g. 'time' or 'forecast_reference_time'),
print string representations of the points/bounds.
Set *points* or *bounds* to False to skip printing those.
"""
if not coord.units.is_time_reference():
raise ValueError(f"{coord.name()} is not a time type coordinate")
if points:
print("Points:")
print(coord.units.num2date(coord.points).astype('str'))
if bounds:
print("Bounds:")
print(coord.units.num2date(coord.bounds).astype('str')) |
✨ Feature Request
Following [this comment] #4499 (comment) (and preceding ones).
If you know what you're doing this isn't actually that hard.
E.G.
coord.units.num2date(coord.bounds).astype('str')
But it isn't so easy to work that out.
How about
Coord.date_strings()
?We can make it cheekily default to the Coord's own points, like
Connectivity.indices_by_src
The text was updated successfully, but these errors were encountered: