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 4 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
21 changes: 20 additions & 1 deletion desc/io/hdf5_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import h5py
import numpy as np
from termcolor import colored

from .core_io import IO, Reader, Writer

Expand Down Expand Up @@ -124,7 +125,25 @@ 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
colored(
"\n"
f"The object attribute '{attr}' was not loaded from the input "
"file.\nThis is likely because the input file containing "
f"'{obj.__class__.__name__}' was created before '{attr}' "
f"became an attribute of objects of class '{obj.__class__}'.\n"
"The user may verify that a default value has been set.\n"
"This warning will persist until the input file is saved with "
"the new object.\n"
"\n"
"Note to developers: Add 'def _set_up(self)' as a method to "
f"class '{obj.__class__}'\n"
"(or the superclass where this new attribute is assigned) that "
f"assigns a value to '{attr}'.\n"
"This method is called automatically when a file is loaded.\n"
"Recall that the testing suite will fail on warnings.",
"blue",
),
RuntimeWarning,
)
continue
if isinstance(loc[attr], h5py.Dataset):
Expand Down
Loading