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 get to avoid KeyError on missing cmiles attribute #300

Merged
merged 14 commits into from
Oct 21, 2024
Merged

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Oct 4, 2024

Description

This fixes the crash described in #299, although it doesn't add any additional checks to warn if every entry was skipped.

Todos

Notable points that this PR has either accomplished or will accomplish.

Questions

  • Should a similar check be performed in TorsionDriveResultCollection? Currently it only tries entry.attributes for the CMILES and will crash if it's not found.

Status

  • Ready to go

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.53%. Comparing base (cc3f23e) to head (89b0564).
Report is 1 commits behind head on main.

Additional details and impacted files

Copy link
Member

@j-wags j-wags left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ntBre. Could you change the print to a warning and try add a test here? Maybe load the real dataset from the original issue and ensure it doesn't crash any more (it's fine if this adds up to 10 sec to CI). Also add a pytest.warns to the test to ensure the warning gets emitted.

It'd be cool to have a helpful message for users who encounter this exact issue in the future, but (per our discussion in our one-on-one) we don't have a preferred workaround for this issue yet, so it's not necessary for this PR to add that.

"canonical_isomeric_explicit_hydrogen_mapped_smiles"
]
)
if not cmiles:
print(f"MISSING CMILES! entry = {entry_name}")
Copy link
Member

@j-wags j-wags Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(blocking) Could you change this to be warnings.warn with a new warning type like MissingCMILESWarning?

@ntBre
Copy link
Contributor Author

ntBre commented Oct 7, 2024

Thanks for the review! I think I covered everything we discussed.

@ntBre ntBre requested a review from j-wags October 7, 2024 22:52
ntBre and others added 6 commits October 9, 2024 15:48
based on these
docs (https://docs.python.org/3/howto/logging.html#when-to-use-logging) warnings
should be used "if the issue is avoidable and the client application should be
modified to eliminate the warning," (like a deprecation warning) while logging a
warning should be used "if there is nothing the client application can do about
the situation, but the event should still be noted." I think this warning is
closer to the latter case, where there's not much a user can do about this, and
this allows us to filter these warnings by default, which I don't think is
possible with the warnings module
@ntBre
Copy link
Contributor Author

ntBre commented Oct 9, 2024

I also quoted this in one of the commit messages, but I'll copy it here as a reason for switching to logging from warnings. In practical terms I just didn't see an easy way to filter a specific warning class by default as we discussed in the meeting yesterday, but I thought the docs were an interesting additional justification.

based on these docs (https://docs.python.org/3/howto/logging.html#when-to-use-logging) warnings
should be used "if the issue is avoidable and the client application should be
modified to eliminate the warning," (like a deprecation warning) while logging a
warning should be used "if there is nothing the client application can do about
the situation, but the event should still be noted." I think this warning is
closer to the latter case, where there's not much a user can do about this, and
this allows us to filter these warnings by default, which I don't think is
possible with the warnings module

Copy link
Member

@j-wags j-wags left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for the revisions and for looking into logging vs. warnings best practices @ntBre!

Please update the release notes before you merge :-)

@ntBre
Copy link
Contributor Author

ntBre commented Oct 15, 2024

Thanks again for the review! I've updated the release notes too. While I was there, I noticed that a couple of the recent entries have minor typos:
image

The first is missing a link and the second has an extra colon (like I had initially too!). Can I fix those while I'm here or should that be separate?

@ntBre ntBre merged commit deb0d92 into main Oct 21, 2024
8 checks passed
@ntBre ntBre deleted the skip-missing-cmiles branch October 21, 2024 21:08
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