-
Notifications
You must be signed in to change notification settings - Fork 16
Allow clearing default material libraries by assigning None
#802
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
base: develop
Are you sure you want to change the base?
Conversation
…material and problem scopes
…r clearing a default library by assigning None.
2af789b
to
ddb420f
Compare
Thanks @Vikranth3140 for this contribution. I'm a bit busy right now and it will be a little while before I can review this. Did you use the help of an LLM (e.g., ChatGPT, claude, Copilot, etc.) to prepare this PR? We are still working on our exact policy, but using LLMs is fine as long as this use is disclosed. |
This is not part of my review, I just noticed that on coveralls I noticed the patch coverage is 80%. We really aim for 100% patch coverage unless a good reason this isn't possible is provided. I thought while you wait on my review you could work on the test coverage. |
Hi, Yes, I had written the base code and optimized it using Copilot and also written the tests/test_material.py using it. |
Hi, so the add_rtd_link is failing because my workflow permissions are read-only and does not accept accept modifications from a PR |
Here is the documentation build: https://montepy--802.org.readthedocs.build/en/802/ Yes I know about this issue and I don't know of a good workaround yet. It's completely fine to ignore that failure though. |
Okay cool |
Hi @MicahGale, is there any update on this PR |
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 still needs some improvements.
- This does not fix #801, but rather #800.
- Some editorial changes for clarity
- The new
update
method is not necessary for #800. It could be helpful, but currently is not being effectively tested. So I would say either remove it or make the testing more thorough to get 100% coverage.
Coverage report because coveralls is currently down. The current CI failure is due to Coveralls being done, so you don't need to worry about it.
htmlcov.zip
|
||
**Features Added** | ||
|
||
* Allow clearing default libraries by assigning ``None`` at material and problem scopes; unset values are omitted from serialization. |
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.
I do not follow the "unset values are omitted from serialization" aspect, and I'm not sure it's true. Also I don't think such a technical detail is needed in a changelog.
This needs to be linked to an issue well. See the below bug fix.
def update(self, other=None, **kwargs): | ||
"""Update the default libraries with the key/value pairs from other, overwriting existing keys. | ||
Parameters | ||
---------- | ||
other : dict or dict-like | ||
Another dict or dict-like object to update from | ||
**kwargs | ||
Additional key-value pairs to update | ||
""" |
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 doc string is rather generic, and is not very specific to this class. It might benefit from an example. I could imagine it being used in the following way (which is not a full example):
mat.default_libraries.update({"nlib": "80c", "plib": "80p"})
That being said this is not required for fixing #800, and could be dropped from this PR if needed.
if other is not None: | ||
if hasattr(other, "items"): |
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 is a user-facing function, so the inputs cannot be trusted. A lot of the type and value enforcement will be handled by __setitem__
, however you will need to ensure that other
is a dictionary prior to iterating over it.
:func:`~montepy.data_inputs.material.Material.default_libraries` acts like a dictionary, | ||
and can accept a string or a :class:`~montepy.particle.LibraryType` as keys. | ||
To clear a default library, assign ``None``: |
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.
To clear a default library, assign ``None``: | |
A default library can be cleared by assigning it to be ``None``: |
:func:`~montepy.data_inputs.material.Material.default_libraries` acts like a dictionary, | ||
and can accept a string or a :class:`~montepy.particle.LibraryType` as keys. | ||
To clear a default library, assign ``None``: |
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.
To clear a default library, assign ``None``: | |
A default library can be cleared by assigning it to be ``None``: |
To set the default libraries for a problem you need to set this dictionary | ||
to a Library or string. | ||
to a Library or string. To clear a default library, assign ``None``. |
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.
To set the default libraries for a problem you need to set this dictionary | |
to a Library or string. | |
to a Library or string. To clear a default library, assign ``None``. | |
To set the default libraries for a problem you need to set the values of this dictionary | |
to a Library or string. | |
to a Library or string. To clear a default library, set the value to ``None``. |
def test_default_libraries_none_setting(_, dl): | ||
"""Test that setting default libraries to None unsets them.""" | ||
# Set a library first | ||
dl["plib"] = "80p" | ||
assert dl["plib"] == Library("80p") |
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.
As discussed the patch coverage is currently 80% so more testing is needed. I suspect most of the needed testing is for more atypical ways to call these changes.
# Test update method with None | ||
dl["nlib"] = "00c" | ||
dl["plib"] = "80p" | ||
dl.update({"plib": None}) |
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 only tests one way that this can be called. You need to also test:
- calling it with just
kwargs
- Calling it with
other
andkwargs
- calling with not a dictionary
other=None
- etc.
Description
This PR implements support for making material and problem-level default libraries “None-able,” addressing Issue #801.
Summary of changes
Updated
__setitem__
fordefault_libraries
mapping:None
to a default library key (e.g.,"nlib"
,"plib"
, orLibraryType.NEUTRON
) now unsets/deletes the entry.None
assignments remain backward-compatible (Library
orstr
).Updated
update()
so that passing{"nlib": None}
or keywordnlib=None
also unsets correctly.Serializer logic verified to omit unset defaults (no
"None"
literal is emitted).Adjusted type checks and docstrings to clarify accepted values (
Library | str | None
).Behavior
Before:
None
.None
raised an error or resulted in an invalid literal"None"
in output.After:
None
.None
now unsets the default, and it is omitted from serialization.Fixes #801
General Checklist
black
version 25.Documentation Checklist
First-Time Contributor Checklist
pyproject.toml
if you wish to do so.Additional Notes for Reviewers
Ensure that: