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

Switch guessers to catching and raising NoDataErrors #4755

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

lilyminium
Copy link
Member

@lilyminium lilyminium commented Oct 20, 2024

Fixes #4749 (maybe?)

Changes made in this Pull Request:

  • Switches errors to NoDataErrors

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

Developers certificate of origin


📚 Documentation preview 📚: https://mdanalysis--4755.org.readthedocs.build/en/4755/

Copy link

codecov bot commented Oct 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.62%. Comparing base (101008b) to head (52adce9).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4755      +/-   ##
===========================================
- Coverage    93.65%   93.62%   -0.03%     
===========================================
  Files          175      187      +12     
  Lines        21564    22631    +1067     
  Branches      3023     3023              
===========================================
+ Hits         20195    21189     +994     
- Misses         925      998      +73     
  Partials       444      444              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

From reading the issue and glancing at the code, changing the raised ValueError to NoDataError makes sense and seems more consistent.

I am not really familiar with the new guesser code so this is just a surface-level review. Other reviews would be great.

@lilyminium I'll leave it to you to gather more opinions if you need them.

@IAlibay IAlibay added this to the Release 2.8.0 milestone Oct 24, 2024
@lilyminium
Copy link
Member Author

@IAlibay could you please have a look to see if this resolves issue #4749?

@yuxuanzhuang
Copy link
Contributor

I think what @IAlibay means is that there is a nested exception error message:

a = np.array([
    [0., 0., 150.], [0., 0., 150.], [200., 0., 150.],
    [0., 0., 150.], [100., 100., 150.], [200., 100., 150.],
    [0., 200., 150.], [100., 200., 150.], [200., 200., 150.]
])
u = mda.Universe(a, n_atoms=9, to_guess=['elements'])

> ...
> NoDataError: This Universe does not contain name information
> During handling of the above exception, another exception occurred:
> ...
> NoDataError: there is no reference attributes in this universeto guess types from

which is kinda ugly. you can explicitly suppress the chaining of exceptions using the from None syntax (see suggestions)

except ValueError:
raise ValueError(
except NoDataError:
raise NoDataError(
"there is no reference attributes"
" (elements, types, or names)"
" in this universe to guess mass from")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
" in this universe to guess mass from")
" in this universe to guess mass from") from None

except AttributeError:
raise ValueError(
except NoDataError:
raise NoDataError(
"there is no reference attributes in this universe"
"to guess types from")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"to guess types from")
"to guess types from") from None

@IAlibay
Copy link
Member

IAlibay commented Oct 25, 2024

I think what @IAlibay means is that there is a nested exception error message:

which is kinda ugly. you can explicitly suppress the chaining of exceptions using the from None syntax (see suggestions)

Yes, thanks so much @yuxuanzhuang, that's exactly what I was looking at! Sorry I conflated that with the error type for some reason.

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

LGTM with @yuxuanzhuang's suggestions.

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.

Guesser checks should wrap NoDataError
4 participants