From 2c56e1a3b470249084ebb2bb621ef7f902e66e9b Mon Sep 17 00:00:00 2001 From: Florian Obersteiner Date: Wed, 23 Feb 2022 09:17:20 +0100 Subject: [PATCH] use f-strings --- src/icartt/dataset.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/icartt/dataset.py b/src/icartt/dataset.py index ee7c3f4..63ac5e5 100644 --- a/src/icartt/dataset.py +++ b/src/icartt/dataset.py @@ -251,7 +251,7 @@ class StandardNormalComments(collections.UserList): for key in self.keywords: if self.keywords[key].data == []: warnings.warn( - "Normal comments: required keyword {:s} is missing.".format(key) # TODO: in genaral: use f-strings + f"Normal comments: required keyword {str(key)} is missing." ) def __init__(self): @@ -350,9 +350,7 @@ class Variable: """Constructor method""" if not self.isValidVariablename(shortname): warnings.warn( - "Variable short name {:s} does not comply with ICARTT standard v2".format( - shortname - ) + f"Variable short name {str(shortname)} does not comply with ICARTT standard v2" ) self.shortname = shortname @@ -490,7 +488,7 @@ class Dataset: try: self.format = Formats(int(dmp[1])) except: - raise ValueError("ICARTT format {:d} not implemented".format(dmp[1])) + raise ValueError(f"ICARTT format {int(dmp[1])} not implemented") # TODO except clause could be re-written like # except ValueError as ve: # raise ValueError(f"ICARTT format {dmp[1]:d} not implemented") from ve @@ -523,7 +521,7 @@ class Dataset: # - comma delimited (yyyy, mm, dd, yyyy, mm, dd). dmp = f.readline() self.dateOfCollection = datetime.datetime.strptime( - "".join(["{:s}".format(x) for x in dmp[0:3]]), "%Y%m%d" + "".join(["{:s}".format(x) for x in dmp[:3]]), "%Y%m%d" ) self.dateOfRevision = datetime.datetime.strptime( "".join(["{:s}".format(x) for x in dmp[3:6]]), "%Y%m%d" @@ -670,9 +668,7 @@ class Dataset: if self.nHeader != nHeaderSuggested: warnings.warn( - "Number of header lines suggested in line 1 ({:d}) do not match actual header lines read ({:d})".format( - nHeaderSuggested, self.nHeader - ) + f"Number of header lines suggested in line 1 ({int(nHeaderSuggested)}) do not match actual header lines read ({int(self.nHeader)})" ) def readData(self, splitChar=","): @@ -823,11 +819,11 @@ class Dataset: ] # Number of SPECIAL comment lines (Integer value indicating the number of lines of special comments, NOT including this line.). - prnt("{:d}".format(len(self.specialComments))) + prnt(f"{len(self.specialComments)}") # Special comments (Notes of problems or special circumstances unique to this file. An example would be comments/problems associated with a particular flight.). _ = [prnt(x) for x in self.specialComments] # Number of Normal comments (i.e., number of additional lines of SUPPORTING information: Integer value indicating the number of lines of additional information, NOT including this line.). - prnt("{:d}".format(self.normalComments.nlines)) + prnt(f"{self.normalComments.nlines}") # Normal comments (SUPPORTING information: This is the place for investigators to more completely describe the data and measurement parameters. The supporting information structure is described below as a list of key word: value pairs. Specifically include here information on the platform used, the geo-location of data, measurement technique, and data revision comments. Note the non-optional information regarding uncertainty, the upper limit of detection (ULOD) and the lower limit of detection (LLOD) for each measured variable. The ULOD and LLOD are the values, in the same units as the measurements that correspond to the flags -7777s and -8888s within the data, respectively. The last line of this section should contain all the short variable names on one line. The key words in this section are written in BOLD below and must appear in this section of the header along with the relevant data listed after the colon. For key words where information is not needed or applicable, simply enter N/A.). # re-create last line out of actual data if missing... if self.normalComments.shortnames == []: -- GitLab