bambinos / bambi

BAyesian Model-Building Interface (Bambi) in Python.
https://bambinos.github.io/bambi/
MIT License
1.08k stars 124 forks source link

Type-hint and type-overload a few common Model methods #790

Open thomasaarholt opened 7 months ago

thomasaarholt commented 7 months ago

Hello!

I have used pymc extensively over the last two years, and have finally had a play with bambi. I really like it - it has some really nice defaults, and the formula syntax is great!

I noticed that some type hinting was missing on the most commonly used Model methods, so I decided to add that. I initially just wanted to add some overload methods to Model.fit, so that it would clearly be returning an InferenceData object when called with the appropriate inference_methods. Then I got a bit carried away, since it wasn't very difficult to add the remaining commonly used methods. I've previously added type hinting to some of the functions in pymc.

I am using pyright to check the types. This is what is used in VSCode for type checking, docstrings and autocompletion. This PR does not change any behaviour or logic, only adds type hinting that make IDEs better at understanding the code.

Here is a screenshot of my editor from before the changes are made:

image

And here they are after:

image

Here is the run.py file in a gist.

tomicapretto commented 7 months ago

Thanks for the contribution @thomasaarholt! I'll let you know what I think once I can review. For now, let's run the CI :)

codecov-commenter commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 90.17%. Comparing base (714ccb7) to head (3afbc00).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #790 +/- ## ========================================== + Coverage 90.14% 90.17% +0.02% ========================================== Files 46 46 Lines 3836 3846 +10 ========================================== + Hits 3458 3468 +10 Misses 378 378 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

thomasaarholt commented 7 months ago

Great! No rush at all, just had some downtime in my Easter break and thought it would be a nice little contribution.