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 type hints to feature detection #337

Merged

Conversation

freemansw1
Copy link
Member

Partially resolves #75 for feature detection only and adds type hints to all function calls. At the same time, I also went through and dealt with some of the easier issues that pylint found.

I started this process in an effort to start to think through our xarray transition. It helped me think through where iris is actually used (which isn't often in feature detection).

Note that to get Literal to work, we will have to increase our Python requirement to 3.8. I think this is reasonable given that 3.7 is EOL and is no longer available to be installed through conda. 3.7 first came out in 2018, but its most recent release was this June. There are two alternatives if we don't want to do this: 1. require the typing_extensions package. This is a new requirement, and all new requirements should be scrutinized, but given that it is from python itself, I think there is a low risk for inclusion. 2. make the types for our options just str, which I think is less preferred.

In the absence of automated matrix testing, I've run tests on my local machine with Python 3.11 and 3.8, both of which pass. There are still a number of linting errors, but c'est la vie.

  • Have you followed our guidelines in CONTRIBUTING.md?
  • Have you self-reviewed your code and corrected any misspellings?
  • Have you written documentation that is easy to understand?
  • Have you written descriptive commit messages?
  • Have you added NumPy docstrings for newly added functions?
  • Have you formatted your code using black?
  • If you have introduced a new functionality, have you added adequate unit tests?
  • Have all tests passed in your local clone?
  • If you have introduced a new functionality, have you added an example notebook?
  • Have you kept your pull request small and limited so that it is easy to review?
  • Have the newest changes from this branch been merged?

@freemansw1 freemansw1 added the Refactor Code that doesn't intend to change the functionality, but instead refactor/clean up. label Sep 10, 2023
@freemansw1 freemansw1 added this to the Version 1.6 milestone Sep 10, 2023
@freemansw1 freemansw1 added the good first issue An ideal issue for new contributors to address label Sep 10, 2023
@codecov
Copy link

codecov bot commented Sep 10, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (85f8f3a) 56.35% compared to head (68447a4) 56.43%.

Additional details and impacted files
@@              Coverage Diff              @@
##           RC_v1.5.x     #337      +/-   ##
=============================================
+ Coverage      56.35%   56.43%   +0.07%     
=============================================
  Files             16       16              
  Lines           3384     3390       +6     
=============================================
+ Hits            1907     1913       +6     
  Misses          1477     1477              
Flag Coverage Δ
unittests 56.43% <100.00%> (+0.07%) ⬆️

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

Files Coverage Δ
tobac/feature_detection.py 84.43% <100.00%> (+0.22%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@freemansw1
Copy link
Member Author

I decided to reverse course and add typing_extensions as a requirement to preserve 3.7 support and because I think it's highly likely that we will need the backporting of typing features at some point.

@w-k-jones
Copy link
Member

I'm pro removing python 3.7 support with the v1.6 update, but including typing_extensions is probably a good idea for now

@freemansw1 freemansw1 added the xarray transition Part of the transition to xarray support label Sep 11, 2023
@freemansw1 freemansw1 marked this pull request as draft September 11, 2023 16:21
@freemansw1
Copy link
Member Author

I've switched this to a draft PR until we get 1.5.1 out. RC_v1.5.x currently lags RC_v1.5_hotfix.

@freemansw1 freemansw1 marked this pull request as ready for review October 2, 2023 15:03
@freemansw1
Copy link
Member Author

With 1.5.1 out, I've marked this as ready for review. I think there's an argument to wait on this (and #341) until v1.6.0, but I think there is no harm in doing so with v1.5.2 as well.

Copy link
Member

@w-k-jones w-k-jones left a comment

Choose a reason for hiding this comment

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

Looks good, my only query is regarding the typing of the min_h1, max_h1 etc... variables for PBCs

tobac/feature_detection.py Show resolved Hide resolved
tobac/feature_detection.py Show resolved Hide resolved
@JuliaKukulies
Copy link
Member

Looks very good - also nice that you addressed some pylint issues in the same go!

Copy link
Collaborator

@harrietgilmour harrietgilmour left a comment

Choose a reason for hiding this comment

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

I really like this addition! It all looks good and a great starting point for adding type hints to the rest of tobac (if that's still the plan).

@freemansw1
Copy link
Member Author

Updated now that we have merged in #293

@freemansw1
Copy link
Member Author

@JuliaKukulies did I get the type for the statistics right? If so, I will go ahead and merge.

@JuliaKukulies
Copy link
Member

@JuliaKukulies did I get the type for the statistics right? If so, I will go ahead and merge.

Yes, looks good!

@freemansw1 freemansw1 merged commit 32923fe into tobac-project:RC_v1.5.x Nov 8, 2023
8 checks passed
@JuliaKukulies JuliaKukulies mentioned this pull request Nov 8, 2023
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue An ideal issue for new contributors to address Refactor Code that doesn't intend to change the functionality, but instead refactor/clean up. xarray transition Part of the transition to xarray support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants