-
Notifications
You must be signed in to change notification settings - Fork 90
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
Use f-strings where possible #205
Conversation
It's faster.
@@ -496,8 +496,7 @@ def fit_NDregion(region, lineshapes, params, amps, bounds=None, | |||
if wmask is None: # default is to include all points in region | |||
wmask = np.ones(shape, dtype='bool') | |||
if wmask.shape != shape: | |||
err = "wmask has incorrect shape:" + str(wmask.shape) + \ | |||
" should be " + str(shape) | |||
err = f"wmask has incorrect shape: {wmask.shape} should be {shape}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space after incorrect shape:
@@ -1546,7 +1546,7 @@ def read_binary(filename, shape=(1), cplex=True, big=True, isfloat=False): | |||
return dic, data.reshape(shape) | |||
|
|||
except ValueError: | |||
warn(str(data.shape) + "cannot be shaped into" + str(shape)) | |||
warn(f"{data.shape} cannot be shaped into {shape}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space before and after "cannot be shaped into".
@@ -2169,9 +2169,9 @@ def read_jcamp(filename, encoding=locale.getpreferredencoding()): | |||
key, value = parse_jcamp_line(line, f) | |||
dic[key] = value | |||
except: | |||
warn("Unable to correctly parse line:" + line) | |||
warn(f"Unable to correctly parse line: {line}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space after line:
.
else: | ||
warn("Extraneous line:" + line) | ||
warn(f"Extraneous line: {line}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space after line:
.
@@ -85,7 +85,7 @@ def _parsejcampdx(filename): | |||
key = _getkey(currentkey) | |||
value = "".join(currentvaluestrings) # collapse | |||
if not value.strip(): | |||
warn("JCAMP-DX key without value:" + key) | |||
warn(f"JCAMP-DX key without value: {key}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space after value:
.
@@ -121,7 +121,7 @@ def _parsejcampdx(filename): | |||
keystr = keysplit[0][2:] # remove "##" already here | |||
valuestr = keysplit[1] | |||
if not keystr: | |||
warn("Empty key in JCAMP-DX line:" + line) | |||
warn(f"Empty key in JCAMP-DX line: {line}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space after line:
.
@@ -571,7 +571,7 @@ def reorder_data(data, shape, torder): | |||
try: | |||
data = data.reshape(shape) | |||
except ValueError: | |||
warn(str(data.shape) + "cannot be shaped into" + str(shape)) | |||
warn(f"{data.shape} cannot be shaped into {shape}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space before and after cannot be shaped into
.
warn("data cannot be re-ordered, returning raw 2D data\n" + | ||
"Provided shape: " + str(shape) + " torder: " + str(torder)) | ||
warn(f"data cannot be re-ordered, returning raw 2D data\n" + | ||
f"Provided shape: {shape} torder: {torder}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space before torder:
.
return dic, data | ||
|
||
try: | ||
data = data.reshape(shape) | ||
except ValueError: | ||
warn(str(data.shape) + "cannot be shaped into" + str(shape)) | ||
warn(f"{data.shape} cannot be shaped into {shape}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space before and after cannot be shaped into
.
@@ -858,7 +858,7 @@ def read_fid_ntraces(filename, shape=None, torder='flat', as_2d=False, | |||
try: | |||
data = data.reshape(shape) | |||
except ValueError: | |||
warn(str(data.shape) + "cannot be shaped into" + str(shape)) | |||
warn(f"{data.shape} cannot be shaped into {shape}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space before and after cannot be shaped into
.
@@ -273,7 +273,7 @@ def run(cpython, script, pass_current_folder=True, use_shell=None, dry=None): | |||
args = [cpython, script] + cd | |||
|
|||
if dry: | |||
MSG("The following command will be executed: \n" + " ".join(args)) | |||
MSG("The following command will be executed:\n" + " ".join(args)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the spurious space before \n
. I am wondering whether the intent was to have \n
after " ".join(args)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure on the intent here. Likely just a typo or overlooked extra character.
Thanks @DimitriPapadopoulos for the PR. I like how f-string make the message more understandable. |
It's faster.
Also a couple small changes here and there.