Skip to content

Commit

Permalink
Making the summary print out of date ranges prettier.
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanwp committed Aug 10, 2016
1 parent 11d6a5c commit 742ea44
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cis/data_io/ungridded_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,21 @@ def summary(self, offset=5):
:param offset: The left hand padding to apply to the text
:return: The summary
"""
from datetime import datetime
string = ''
string += '{pad:{width}}Long name = {lname}\n'.format(pad=' ', width=offset, lname=self.long_name)
string += '{pad:{width}}Standard name = {sname}\n'.format(pad=' ', width=offset, sname=self.standard_name)
string += '{pad:{width}}Units = {units}\n'.format(pad=' ', width=offset, units=self.units)
if self.calendar:
string += '{pad:{width}}Calendar = {cal}\n'.format(pad=' ', width=offset, cal=self.calendar)
string += '{pad:{width}}Missing value = {mval}\n'.format(pad=' ', width=offset, mval=self.missing_value)
string += '{pad:{width}}Range = {range}\n'.format(pad=' ', width=offset, range=self.range)
# str(tuple) returns repr(obj) on each item in the tuple, if we have a datetime tuple then we want str(obj)
# instead. Just make that ourselves here instead (as a str to avoid the extra quotes if we make a 'real' tuple)
if isinstance(self.range[0], datetime):
range_tuple = '({}, {})'.format(*self.range)
else:
range_tuple = self.range
string += '{pad:{width}}Range = {range}\n'.format(pad=' ', width=offset, range=range_tuple)
string += '{pad:{width}}History = {history}\n'.format(pad=' ', width=offset, history=self.history)
if self.misc:
string += '{pad:{width}}Misc attributes: \n'.format(pad=' ', width=offset)
Expand Down

0 comments on commit 742ea44

Please sign in to comment.