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

Construct ModelContainer from a Sequence #164

Merged
merged 3 commits into from
May 11, 2023

Conversation

bmorris3
Copy link
Contributor

@bmorris3 bmorris3 commented Apr 25, 2023

It's occasionally convenient to construct a ModelContainer with an init arg that may be either (1) a string path/DataModel; or also (2) an existing ModelContainer instance. (1) is currently supported in roman_datamodels and jwst, while (2) is supported in jwst but not roman_datamodels.

In this tiny PR, I've allowed rdm ModelContainers to be constructed from lists or subclasses of collections.abc.Sequence, so that the expected behavior is recovered.

Checklist

@bmorris3 bmorris3 requested review from a team and WilliamJamieson as code owners April 25, 2023 19:18
@codecov
Copy link

codecov bot commented Apr 25, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (c4557bb) 96.72% compared to head (e1f319f) 96.74%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #164      +/-   ##
==========================================
+ Coverage   96.72%   96.74%   +0.01%     
==========================================
  Files           8        8              
  Lines        1100     1106       +6     
==========================================
+ Hits         1064     1070       +6     
  Misses         36       36              
Impacted Files Coverage Δ
tests/test_models.py 98.22% <100.00%> (+0.02%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@PaulHuwe PaulHuwe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the Change log.

@bmorris3 bmorris3 force-pushed the modelcontainer-init branch from d8383c9 to 45956f2 Compare April 26, 2023 14:30
@PaulHuwe
Copy link
Collaborator

In addition, you need to add the PLWishMaster regression test run.

Copy link
Collaborator

@mairanteodoro mairanteodoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@bmorris3
Copy link
Contributor Author

@PaulHuwe Here's the regression test. And thanks again for the help!

Copy link
Collaborator

@WilliamJamieson WilliamJamieson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fix the merge conflict in CHANGES.rst

@@ -405,7 +405,7 @@ def __init__(self, init=None, iscopy=False, memmap=False, return_open=True, save
if init is None:
# don't populate container
pass
elif isinstance(init, list):
elif isinstance(init, (list, Sequence)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elif isinstance(init, (list, Sequence)):
elif isinstance(init, Iterable):

This will allow it to handle anything that follows the iterable protocol, the later checks will cover off any cases where this does not make sense.

Note Iterable is a part of the abc.collections builtin Python module, so line 16 will need to be updated in addition to this change in order for it to work.

Copy link
Collaborator

@PaulHuwe PaulHuwe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with @WilliamJamieson's comments.

@bmorris3 bmorris3 force-pushed the modelcontainer-init branch 2 times, most recently from 8e2de07 to dd06dd1 Compare May 11, 2023 13:24
@bmorris3
Copy link
Contributor Author

bmorris3 commented May 11, 2023

I'll rebase to fix the new conflict, but @PaulHuwe / @WilliamJamieson: could you confirm that the last remaining test failure is unrelated? Thanks.

@WilliamJamieson
Copy link
Collaborator

I'll rebase to fix the new conflict, but @PaulHuwe / @WilliamJamieson: could you confirm that the last remaining test failure is unrelated? Thanks.

The failure should have been fixed by #174. Try rebasing again with those changes included.

@bmorris3 bmorris3 force-pushed the modelcontainer-init branch from dd06dd1 to e1f319f Compare May 11, 2023 18:46
@WilliamJamieson
Copy link
Collaborator

I'm merging this before anything else breaks stuff (I think spacetelescope/rad#255 just did but the CI is green now).

@WilliamJamieson WilliamJamieson merged commit 73d864d into spacetelescope:main May 11, 2023
@bmorris3
Copy link
Contributor Author

Thanks @WilliamJamieson et al!

mairanteodoro pushed a commit to mairanteodoro/roman_datamodels that referenced this pull request May 11, 2023
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

Successfully merging this pull request may close these issues.

4 participants