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

Force array validation when initializing a datamodel from another datamodel of different type #403

Merged
merged 2 commits into from
Feb 18, 2025

Conversation

emolter
Copy link
Contributor

@emolter emolter commented Feb 13, 2025

Closes #307

This PR fixes a bug that allowed initialization of a datamodel from a different datamodel with an incompatible schema. For example, a CubeModel could be used as input to an ImageModel, e.g., model = ImageModel(CubeModel(10,10,10)), leading to a situation where the ImageModel contained a 3-D data array that was incompatible with its schema ndim. This PR forces validation of arrays when attempting this kind of assignment.

Tasks

  • update or add relevant tests
  • update relevant docstrings and / or docs/ page
  • Does this PR change any API used downstream? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see below for change types)
    • run jwst regression tests with this branch installed ("git+https://github.com/<fork>/stdatamodels@<branch>")
news fragment change types...
  • changes/<PR#>.feature.rst: new feature
  • changes/<PR#>.bugfix.rst: fixes an issue
  • changes/<PR#>.doc.rst: documentation change
  • changes/<PR#>.removal.rst: deprecation or removal of public API
  • changes/<PR#>.misc.rst: infrastructure or miscellaneous change

@emolter
Copy link
Contributor Author

emolter commented Feb 13, 2025

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.42%. Comparing base (4e83608) to head (eeb3401).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #403      +/-   ##
==========================================
+ Coverage   78.16%   78.42%   +0.25%     
==========================================
  Files         115      115              
  Lines        5144     5155      +11     
==========================================
+ Hits         4021     4043      +22     
+ Misses       1123     1112      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@emolter
Copy link
Contributor Author

emolter commented Feb 13, 2025

Failing JWST regression tests are due to one instance that took advantage of this bug to initialize a CubeModel with an ImageModel. So this PR is blocked until spacetelescope/jwst#9192 is merged

@emolter emolter marked this pull request as ready for review February 13, 2025 19:18
@emolter emolter requested a review from a team as a code owner February 13, 2025 19:18
@emolter emolter requested a review from braingram February 13, 2025 19:38
@emolter
Copy link
Contributor Author

emolter commented Feb 13, 2025

@jdavies-st this is the other fix associated with the validation issue you raised a while back, please feel free to review if you are interested

Copy link
Contributor

@jdavies-st jdavies-st left a comment

Choose a reason for hiding this comment

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

Changes look good.

A meta question is why are there are tree of tests under src? The whole point of the src layout is to separate the package from the tests dir and not have the tests there, as recommended by Python packaging guides for the last decade and by pytest.

@tapastro
Copy link
Collaborator

Pytest describes both options as valid here, including a method involving both: https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#choosing-a-test-layout-import-rules

Placing unit tests in subdirectories inline with their source follows jwst convention and makes it clear which tests are meant to cover which code. I don't see a overruling reason to extricate test files from src/stdatamodels/jwst/{datamodels/transforms}.

Copy link
Collaborator

@braingram braingram left a comment

Choose a reason for hiding this comment

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

LGTM.

@emolter emolter merged commit 0595249 into spacetelescope:main Feb 18, 2025
19 checks passed
@emolter emolter deleted the issue-307-models branch February 18, 2025 14:27
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.

datamodels doesn't validate arrays in some cases
4 participants