Skip to content

adding the API contracts#7

Open
MikeLippincott wants to merge 8 commits intoWayScience:mainfrom
MikeLippincott:data_contracts
Open

adding the API contracts#7
MikeLippincott wants to merge 8 commits intoWayScience:mainfrom
MikeLippincott:data_contracts

Conversation

@MikeLippincott
Copy link
Copy Markdown
Member

Description

This PR adds data contracts for validating inputs and outputs. This is an initial step and will be added to as other modules get added in the future.

What kind of change(s) are included?

  • Documentation (changes docs or other related content)
  • Bug fix (fixes an issue).
  • Enhancement (adds functionality).
  • Breaking change (these changes would cause existing functionality to not work as expected).

Checklist

Please ensure that all boxes are checked before indicating that this pull request is ready for review.

  • I have read and followed the CONTRIBUTING.md guidelines.
  • I have searched for existing content to ensure this is not a duplicate.
  • I have performed a self-review of these additions (including spelling, grammar, and related).
  • These changes pass all pre-commit checks.
  • I have added comments to my code to help provide understanding
  • I have added a test which covers the code changes found within this PR
  • I have deleted all non-relevant text in this pull request template.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Member

@d33bs d33bs left a comment

Choose a reason for hiding this comment

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

Nice job! I'm requesting changes mainly because I think there's existing tooling you could make use of to reduce the amount of new code you need to create.

If you feel strongly about keeping things as-is just let me know and I'll circle back to give this more thought.

Comment thread README.md Outdated
Comment thread src/zedprofiler/contracts.py
Comment thread src/zedprofiler/contracts.py
Comment thread src/zedprofiler/contracts.py
Comment thread src/zedprofiler/contracts.py
Comment thread tests/conftest.py Outdated
Comment thread tests/conftest.py Outdated
Comment thread tests/conftest.py
Comment thread tests/test_package_exports.py Outdated
Comment thread pyproject.toml Outdated
@MikeLippincott MikeLippincott requested a review from d33bs May 6, 2026 18:24
Copy link
Copy Markdown
Member

@d33bs d33bs left a comment

Choose a reason for hiding this comment

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

Great work! LGTM, left a few comments about possible improvements.

Comment thread CONTRIBUTING.md
When running `just all` locally, the coverage badge will not be updated since it is intended to be updated as part of the CI workflow.

```
just all
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider providing an indication of "which" "all" we're meaning when we call this from just. For example all-prep or something could help distinguish what you mean in the project.

Comment thread CONTRIBUTING.md
```

the coverage badge will be automatically updated as part of the workflow.
If you want to update the covererage then just run:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
If you want to update the covererage then just run:
If you want to update the coverage, run:

Comment thread CONTRIBUTING.md

### Linting, testing, coverage, and updating coverage badges

We apply a custom script to update our coverage badge in the README during our CI workflow.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome! Thanks for spelling this out.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make sense to add this as part of the tests suite? You could invoke just this test if needed for the coverage update (perhaps using an ignore pattern or marks or both).

)


class ImageArrayModel(BaseModel):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably for a future PR or idea work: consider using LinkML to help specify a generated pydantic model for this and other classes here. Doing this might free the work up for new opportunities.



@beartype
def validate_image_array_shape_contracts(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this be a class method where relevant, perhaps as something called from the constructor when invoked? Same comments about the other validation methods here. Could be this is a wrong assumption in terms of your architectural intent.

Comment on lines +382 to +383
except Exception as e:
raise ContractError(f"Return schema validation failed: {e}")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With this and other exceptions I recommend being more specific with the exception (Exception is super broad and could entail other kinds of failures we shouldn't pass along to the dependents of this function).

Comment on lines +430 to +439
def get_pandera_image_schema() -> pa.SeriesSchema:
"""
Get Pandera schema for image array validation.

Returns
-------
pa.SeriesSchema
Pandera schema for numeric arrays
"""
return create_image_array_schema()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a super thin function! Do we need it? If not, ditch it, it will make maintenance easier long-term (fewer abstractions the better). Think: every abstraction object must justify its existence with value-added operations. If it's just deadweight and adds an additional onion-layer without assisting our goals, remove it quickly and outright.

Comment on lines +23 to +28
(areasizeshape, "areasizeshape.compute is not implemented yet"),
(colocalization, "colocalization.compute is not implemented yet"),
(granularity, "granularity.compute is not implemented yet"),
(intensity, "intensity.compute is not implemented yet"),
(neighbors, "neighbors.compute is not implemented yet"),
(texture, "texture.compute is not implemented yet"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool! 😎

Comment thread .gitignore

# PyPI configuration file
.pypirc
data/*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this dir be incorporated into the tests suite?

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.

3 participants