-
Notifications
You must be signed in to change notification settings - Fork 168
Enable and improve mypy typechecking #2422
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
Open
VeckoTheGecko
wants to merge
15
commits into
Parcels-code:v4-dev
Choose a base branch
from
VeckoTheGecko:enable-mypy
base: v4-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9e9b1b1
update mypy config
VeckoTheGecko c5a467f
Remove unused function
VeckoTheGecko 11f023f
Typing fixes
VeckoTheGecko 1d1750d
Add CfAxes to parcels._typing
VeckoTheGecko 1b6df45
Add type annotations to convert.py
VeckoTheGecko 6ec53a6
Fix type annotations
VeckoTheGecko 5d53fee
Ignore select mypy errors
VeckoTheGecko fc93dd7
Fix "import-untyped" errors
VeckoTheGecko 46c5988
Fix type annotations
VeckoTheGecko 3a18f15
Make TimeInterval into Generic class
VeckoTheGecko a25ab17
Fix type annotations
VeckoTheGecko e9bc355
Fix type annotations
VeckoTheGecko 07c6c3f
enable typechecking CI
VeckoTheGecko 18df90d
Update mypy config
VeckoTheGecko 401b6f5
Review feedback
VeckoTheGecko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import numpy as np | ||
|
|
@@ -9,8 +8,8 @@ | |
| from parcels._core.utils.time import timedelta_to_float | ||
|
|
||
| if TYPE_CHECKING: | ||
| from parcels import XGrid | ||
| from parcels._core.field import Field | ||
| from parcels.xgrid import XGrid | ||
|
|
||
|
|
||
| GRID_SEARCH_ERROR = -3 | ||
|
|
@@ -21,7 +20,7 @@ | |
| def _search_1d_array( | ||
| arr: np.array, | ||
| x: float, | ||
| ) -> tuple[int, int]: | ||
| ) -> tuple[np.array[int], np.array[float]]: | ||
| """ | ||
| Searches for particle locations in a 1D array and returns barycentric coordinate along dimension. | ||
|
|
||
|
|
@@ -63,14 +62,14 @@ def _search_1d_array( | |
| return np.atleast_1d(index), np.atleast_1d(bcoord) | ||
|
|
||
|
|
||
| def _search_time_index(field: Field, time: datetime): | ||
| def _search_time_index(field: Field, time: float): | ||
| """Find and return the index and relative coordinate in the time array associated with a given time. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| field: Field | ||
|
|
||
| time: datetime | ||
| time: float | ||
| This is the amount of time, in seconds (time_delta), in unix epoch | ||
| Note that we normalize to either the first or the last index | ||
| if the sampled value is outside the time value range. | ||
|
|
@@ -172,6 +171,8 @@ def _search_indices_curvilinear_2d( | |
| """ | ||
| if np.any(xi): | ||
| # If an initial guess is provided, we first perform a point in cell check for all guessed indices | ||
| assert xi is not None | ||
| assert yi is not None | ||
|
Comment on lines
+174
to
+175
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own understanding; why are these new lines needed? |
||
| is_in_cell, coords = curvilinear_point_in_cell(grid, y, x, yi, xi) | ||
| y_check = y[is_in_cell == 0] | ||
| x_check = x[is_in_cell == 0] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should calling this function not be part of convert?
Once a user requests a FieldSet, do we really want to still change field names? There would be no way to override that for a user anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only moving these here since its only use is in the ux fieldset ingestion - and that hasn't yet moved to convert. I'm happy either way (I thought having it here with the other functionality was neater, especially since we're probably going to outright drop this functionality due to us not doing U and V discovery in convert.py)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, clear. Then perhaps add a TODO that we will likely drop this function in the near future?