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

feat: boost-histogram 1.0 compatibility and typing updates #204

Merged
merged 7 commits into from
Mar 22, 2021

Conversation

alexander-held
Copy link
Member

@alexander-held alexander-held commented Mar 16, 2021

This enables support for boost-histogram>=1.0.0. Subclassing Histogram requires a family keyword argument (optional starting with boost-histogram 1.0.1), and the boost-histogram library is now typed.

resolves #201

Overview of changes

* support and require boost-histogram>=1.0.0
* improved type checking via pre-commit
* added test for histogram properties
* skip mypy in CI for Python 3.7

Typing changes

For reading yields and variances, switch to using h.values() and h.variances() instead of h.view().value and h.view().variance. The view()-based method is still used for writing yields / variances directly.

Calling numpy functions with values/variances requires a # type: ignore, as does setting values via view().
See scikit-hep/boost-histogram#527 and scikit-hep/boost-histogram#525 (comment)). Some of these # type: ignore may possibly be removed in the future with boost-histogram updates.

The typing revealed a small typing bug in cabinetry.route, which will be resolved in a separate PR (here only temporarily fixed via # type: ignore).

CI / pre-commit updates

The CI is updated to skip mypy with Python 3.7, since the boost-histogram syntax requires at least Python 3.8 (see scikit-hep/boost-histogram#525 (comment)).

For type checking, the requirement is boost-histogram>=1.0.1 due to scikit-hep/boost-histogram#525 (comment). The pre-commit version requirement is set accordingly. boost-histogram 1.0.0 will fail with mypy due to two typing bugs (ellipsis/constructor), see also 1.0.1 changelog.

To get mypy working correctly in pre-commit, also adding boost-histogram to the environment requirements (and adding typed numpy at the same time).

Other notes

Also adding a test for Histogram properties.

@alexander-held alexander-held changed the title feat: boost-histogram>1.0.0 compatibility and typing feat: boost-histogram 1.0 compatibility and extended type checks Mar 22, 2021
@codecov
Copy link

codecov bot commented Mar 22, 2021

Codecov Report

Merging #204 (35a0e14) into master (2911813) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #204   +/-   ##
=======================================
  Coverage   98.25%   98.25%           
=======================================
  Files          15       15           
  Lines        1716     1717    +1     
  Branches      267      267           
=======================================
+ Hits         1686     1687    +1     
  Misses         28       28           
  Partials        2        2           
Impacted Files Coverage Δ
src/cabinetry/contrib/histogram_creation.py 100.00% <100.00%> (ø)
src/cabinetry/histo.py 100.00% <100.00%> (ø)
src/cabinetry/route.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2911813...35a0e14. Read the comment docs.

@alexander-held alexander-held changed the title feat: boost-histogram 1.0 compatibility and extended type checks feat: boost-histogram 1.0 compatibility and typing updates Mar 22, 2021
@alexander-held alexander-held merged commit 076c529 into master Mar 22, 2021
@alexander-held alexander-held deleted the feat/histogram-typing branch March 22, 2021 15:23
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.

Set family when inheriting from boost-histogram
1 participant