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

Looping over models during save_results doesn't work for non-list Sequence #218

Open
emolter opened this issue Jan 27, 2025 · 0 comments
Open

Comments

@emolter
Copy link
Collaborator

emolter commented Jan 27, 2025

A non-list but list-like object (e.g., the JWST ModelContainer) should be saved in the same way as a list of models if it does not have its own save() method. However, this is not what currently happens, because

if not isinstance(step_result, list | tuple):
checks specifically for list, not anything that looks like a list.

See the unit tests below.

def test_save_list(tmp_cwd, model_list):
    """ensure all models are saved using the model's save method. This test passes"""
    step = StepWithModel()
    step.run(model_list)
    for i in range(3):
        assert (tmp_cwd / f"test{i}-saved.txt").exists()

def test_save_container(tmp_cwd, model_list):
    """ensure list-like save still works for non-list sequence.

    This test fails on an AssertionError. step runs fine, but nothing is saved at all.
    Behavior should be changed so that this test passes.
    """
    container = SimpleContainer(model_list)
    step = StepWithModel()
    step.run(container)
    for i in range(3):
        assert (tmp_cwd / f"test{i}-saved.txt").exists()

Note these make use of the SimpleContainer and StepWithModel classes here:

class SimpleContainer(Sequence):

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

No branches or pull requests

1 participant