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

Improve warning for missing IOable attributes #1095

Merged
merged 6 commits into from
Jul 4, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion desc/io/hdf5_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,24 @@ def read_obj(self, obj, where=None):
for attr in obj._io_attrs_:
if attr not in loc.keys():
warnings.warn(
"Save attribute '{}' was not loaded.".format(attr), RuntimeWarning
f"Save attribute '{attr}' was not loaded from the input file.\n"
"This is likely because the file from which you are loading the "
f"Python object '{obj.__class__.__name__}' was created "
f"prior to the time '{attr}' "
f"became an attribute of objects of the class '{obj.__class__}'.\n"
"\n"
"Note to developers: Add 'def _set_up(self)' as a method to class "
unalmis marked this conversation as resolved.
Show resolved Hide resolved
f"{obj.__class__}\n"
"(or the superclass where this new attribute is assigned) that "
f"assigns some default value to '{attr}' for old objects.\n"
"This method will be called automatically when a file is loaded.\n"
"\n"
"This warning will continue to be raised until the file is saved "
"with an updated object, even if the _set_up method assigns "
"the missing attribute correctly.\n"
"Our testing suite will fail on warnings, so developers may want "
"to comment out this warning until the input files are updated.\n",
RuntimeWarning,
)
continue
if isinstance(loc[attr], h5py.Dataset):
Expand Down
Loading