Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use f-strings where possible#205

Merged
jjhelmus merged 1 commit into
jjhelmus:masterfrom
DimitriPapadopoulos:f-strings
Nov 15, 2023
Merged

Use f-strings where possible#205
jjhelmus merged 1 commit into
jjhelmus:masterfrom
DimitriPapadopoulos:f-strings

Conversation

@DimitriPapadopoulos
Copy link
Copy Markdown
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Oct 1, 2023

It's faster.

Also a couple small changes here and there.

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
Copy Markdown
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:

Comment thread nmrglue/fileio/bruker.py

except ValueError:
warn(str(data.shape) + "cannot be shaped into" + str(shape))
warn(f"{data.shape} cannot be shaped into {shape}")
Copy link
Copy Markdown
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".

Comment thread nmrglue/fileio/bruker.py
dic[key] = value
except:
warn("Unable to correctly parse line:" + line)
warn(f"Unable to correctly parse line: {line}")
Copy link
Copy Markdown
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:.

Comment thread nmrglue/fileio/bruker.py
warn(f"Unable to correctly parse line: {line}")
else:
warn("Extraneous line:" + line)
warn(f"Extraneous line: {line}")
Copy link
Copy Markdown
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:.

Comment thread nmrglue/fileio/jcampdx.py
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
Copy Markdown
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:.

Comment thread nmrglue/fileio/jcampdx.py
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
Copy Markdown
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:.

Comment thread nmrglue/fileio/varian.py
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
Copy Markdown
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.

Comment thread nmrglue/fileio/varian.py
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
Copy Markdown
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:.

Comment thread nmrglue/fileio/varian.py
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
Copy Markdown
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.

Comment thread nmrglue/fileio/varian.py
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
Copy Markdown
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.

Comment thread nmrglue/util/xcpy.py

if dry:
MSG("The following command will be executed: \n" + " ".join(args))
MSG("The following command will be executed:\n" + " ".join(args))
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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