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

Add variables argument to the DatacubeExtension apply method #782

Merged
merged 4 commits into from
Apr 4, 2022

Conversation

itcarroll
Copy link
Contributor

@itcarroll itcarroll commented Mar 31, 2022

Related Issue(s):

Description:

An optional argument is added to the DatacubeExtension.apply method called variables and handed off to the variable setter. The argument is optional because Variable Objects are optional in the datacube extension spec.

A new test_apply_variables method for the DatacubeTest class does a round-trip check on a variable present in the example item using apply.

PR Checklist:

  • Code is formatted (run pre-commit run --all-files)
  • Tests pass (run scripts/test)
  • Documentation has been updated to reflect changes, if applicable
  • This PR maintains or improves overall codebase code coverage.
  • Changes are added to the CHANGELOG. See the docs for information about adding to the changelog.

@itcarroll
Copy link
Contributor Author

I don't have a lot of experience with type hints, so I'm not sure what to do about the following test failure:

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

tests/extensions/test_datacube.py:94: error: Item "None" of "Optional[Dict[str, Variable]]" has no attribute "popitem"  [union-attr]
tests/extensions/test_datacube.py:98: error: Value of type "None" is not indexable  [index]

Is there a convention for checking a @property for None, or using try/except, that I should employ here?

@duckontheweb
Copy link
Contributor

I don't have a lot of experience with type hints, so I'm not sure what to do about the following test failure:

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

tests/extensions/test_datacube.py:94: error: Item "None" of "Optional[Dict[str, Variable]]" has no attribute "popitem"  [union-attr]
tests/extensions/test_datacube.py:98: error: Value of type "None" is not indexable  [index]

Is there a convention for checking a @property for None, or using try/except, that I should employ here?

We have mostly been handling this within the tests by using something like the following:

cube = DatacubeExtension.ext(item)
cube_variables = cube.variables
assert cube_variables is not None
key, value = cube_variables.popitem()

It's a bit verbose, but mypy picks up on the assert statement and knows that it can't be None after that point.

@itcarroll
Copy link
Contributor Author

I'll include a commit updating the changelog when/if workflow approval is granted, which I presume will do the coverage check.

Copy link
Contributor

@duckontheweb duckontheweb left a comment

Choose a reason for hiding this comment

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

Thanks for catching and fixing this @itcarroll! I'll merge once the CHANGELOG has been updated.

@itcarroll
Copy link
Contributor Author

Added to the CHANGELOG. It looks like the coverage workflow still requires approval to run.

@itcarroll
Copy link
Contributor Author

Coverage at 8964f5c at 94.58 equivalent to main at 07816f5e. Not sure why Codecov didn't report back here.

@duckontheweb duckontheweb merged commit cf431ad into stac-utils:main Apr 4, 2022
@duckontheweb
Copy link
Contributor

Coverage at 8964f5c at 94.58 equivalent to main at 07816f5e. Not sure why Codecov didn't report back here.

Yeah, I've noticed really long lag times in Codecov posting back to the PR and sometimes it seems to take a few CI runs before it triggers. Looks like things are good on that front, thanks for the work on this!

@duckontheweb duckontheweb added this to the 1.5.0 milestone May 4, 2022
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.

DatacubeExtension.apply is unaware of variables
2 participants