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

fix: Add TYPE_CHECKING guard for numpy.typing #2208

Merged
merged 5 commits into from
May 18, 2023

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented May 17, 2023

Description

Resolves #2207

The addition of typing.TYPE_CHECKING avoids situations in which the version of NumPy (whose lower bounds is enforced by SciPy) doesn't have numpy.typing, which was added in NumPy v1.21.0.

To avoid drops in code coverage at the patch level, exclude if TYPE_CHECKING: from the coverage report by using the exclude_also option.

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* The addition of typing.TYPE_CHECKING avoids situations in which
  the version of NumPy (whose lower bounds is enforced by SciPy)
  doesn't have numpy.typing, which was added in NumPy v1.21.0.
* Exclude lines that match 'if TYPE_CHECKING:' from the coverage
  report to avoid artificial drops in code coverage.
   - c.f. https://coverage.readthedocs.io/en/stable/excluding.html#advanced-exclusion

Co-authored-by: Giordon Stark <kratsg@gmail.com>

* The addition of typing.TYPE_CHECKING avoids situations in which
  the version of NumPy (whose lower bounds is enforced by SciPy)
  doesn't have numpy.typing, which was added in NumPy v1.21.0.
@matthewfeickert matthewfeickert added fix A bug fix need-to-backport tmp label until can be backported to patch release branch labels May 17, 2023
@matthewfeickert matthewfeickert self-assigned this May 17, 2023
@matthewfeickert matthewfeickert added the type checking Related to types and type checking label May 17, 2023
@matthewfeickert
Copy link
Member Author

Example of things working:

$ docker run --rm -ti python:3.8 /bin/bash
root@34efcf32f365:/# python -m venv venv && . venv/bin/activate
(venv) root@34efcf32f365:/# python -m pip --quiet install --upgrade pip setuptools wheel
(venv) root@34efcf32f365:/# python -m pip --quiet install --upgrade 'numpy==1.17.3' 'scipy==1.5.1'
venv) root@34efcf32f365:/# git clone --branch fix/guard-numpy-typing --single-branch https://github.com/scikit-hep/pyhf
Cloning into 'pyhf'...
...
(venv) root@34efcf32f365:/# cd pyhf
(venv) root@34efcf32f365:/pyhf# python -m pip --quiet install --upgrade .
(venv) root@34efcf32f365:/pyhf# cd
(venv) root@34efcf32f365:~# python -m pip list | grep 'numpy\|scipy'
numpy                1.17.3
scipy                1.5.1
(venv) root@34efcf32f365:~# python -c 'import pyhf'
(venv) root@34efcf32f365:~# echo $?
0

@codecov
Copy link

codecov bot commented May 17, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (22c1699) 98.30% compared to head (771f64d) 98.30%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2208   +/-   ##
=======================================
  Coverage   98.30%   98.30%           
=======================================
  Files          69       69           
  Lines        4533     4533           
  Branches      801      801           
=======================================
  Hits         4456     4456           
  Misses         45       45           
  Partials       32       32           
Flag Coverage Δ
contrib 97.88% <100.00%> (ø)
doctest 61.12% <100.00%> (ø)
unittests-3.10 96.31% <100.00%> (ø)
unittests-3.11 96.31% <100.00%> (ø)
unittests-3.8 96.33% <100.00%> (ø)
unittests-3.9 96.36% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/pyhf/tensor/numpy_backend.py 98.61% <100.00%> (ø)

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

@matthewfeickert matthewfeickert merged commit 0efb2ee into main May 18, 2023
@matthewfeickert matthewfeickert deleted the fix/guard-numpy-typing branch May 18, 2023 00:01
@matthewfeickert matthewfeickert removed the need-to-backport tmp label until can be backported to patch release branch label May 18, 2023
matthewfeickert added a commit that referenced this pull request May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix A bug fix type checking Related to types and type checking
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add stricter version guards for NumPy
2 participants