Skip to content
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

Merged
merged 1 commit into from
Nov 15, 2023
Merged

Use f-strings where possible #205

merged 1 commit into from
Nov 15, 2023

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Oct 1, 2023

It's faster.

Also a couple small changes here and there.

@@ -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}"
Copy link
Contributor Author

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}")
Copy link
Contributor Author

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}")
Copy link
Contributor Author

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}")
Copy link
Contributor Author

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}")
Copy link
Contributor Author

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}")
Copy link
Contributor Author

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}")
Copy link
Contributor Author

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}")
Copy link
Contributor Author

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}")
Copy link
Contributor Author

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}")
Copy link
Contributor Author

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))
Copy link
Contributor Author

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).

Copy link
Owner

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.

@DimitriPapadopoulos DimitriPapadopoulos marked this pull request as ready for review October 1, 2023 08:35
@jjhelmus
Copy link
Owner

Thanks @DimitriPapadopoulos for the PR. I like how f-string make the message more understandable.

@jjhelmus jjhelmus merged commit 5dd3ab9 into jjhelmus:master Nov 15, 2023
@DimitriPapadopoulos DimitriPapadopoulos deleted the f-strings branch November 15, 2023 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants