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
added ValueError for unknown densities #2775
Conversation
Codecov Report
@@ Coverage Diff @@
## RELEASE_next_minor #2775 +/- ##
======================================================
+ Coverage 78.14% 78.45% +0.30%
======================================================
Files 203 203
Lines 30681 31281 +600
Branches 6704 6871 +167
======================================================
+ Hits 23976 24540 +564
- Misses 4963 4978 +15
- Partials 1742 1763 +21
Continue to review full report at Codecov.
|
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.
This looks good, it needs a test and to make the PR to the RELEASE_next_patch
branch because it is a bug fix.
To avoid pulling change from the RELEASE_next_minor
branch, the base branch will need to changed, see https://hyperspy.readthedocs.io/en/stable/dev_guide/git.html#changing-base-branch for explanation. If you prefer, I can sort it out before merging.
density = sum_densities / sum_weight | ||
return np.where(sum_weight == 0.0, 0.0, density) | ||
except TypeError : | ||
raise ValueError( |
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.
A test is needed to cover this case, you can simply add your example from #2775 in
def test_density_of_mixture(): |
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.
It needs a changelog entry in the upcoming_changes
folder too - see upcoming_changes/README.rst
!
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.
Thanks, looks good. A few commits are unnecessary and I will remove them before merging.
Description of the change
Some entries of the elements database have unknown densities due to their very high radioactivity : Astate and Francium. When calling the function
_density_of_mixture
fromhyperspy.misc.material
with these elements it would raise aTypeError
with a difficult to understand message.With this PR, the function raises a
ValueError
with a more understandable error message.Progress of the PR
Minimal example of the bug fix or the new feature
New output