Repository navigation
[BUG FIX] Field.igrid set by reconstruct_fields() - #3018
Merged
Merged
Conversation
erikvansebille
approved these changes
Oct 29, 2026
erikvansebille
left a comment
Member
There was a problem hiding this comment.
Looks good to me - just two small comments below
Comment on lines
+111
to
+116
| try: | ||
| return self._igrid | ||
| except AttributeError as e: | ||
| raise AttributeError( | ||
| f"{type(self).__name__} doesn't have an igrid defined for it. Use `.igrid = ...`" | ||
| ) from e |
Member
There was a problem hiding this comment.
Is this not overly cautious? Since users don't set en get igrid themselves, can't we assume it's accessed properly? Plus, python will throw an error anyways?
Contributor
Author
There was a problem hiding this comment.
I think that is a fair assumption, removed in 980ddf4
Comment on lines
+120
to
+123
| if value < 0: | ||
| raise ValueError( | ||
| f"igrid of Field {self.name!r} must be a non-negative index into FieldSet.gridset, got {value}. " | ||
| ) |
Member
There was a problem hiding this comment.
Again, overly cautious? Is there a case where a user would put in a negative number?
Contributor
Author
There was a problem hiding this comment.
Agreed, plus the new test should catch any cases where this occurs and causes problems. Removed in 980ddf4
erikvansebille
approved these changes
Oct 29, 2026
erikvansebille
left a comment
Member
There was a problem hiding this comment.
Looks good, happy to be merged!
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Currently,
Field.igridis always set to-1by the field constructor. This causes issues indexing into the correct grid during PIC checks for fieldsets that have more than one underlying grid, since_eiis set usingigrid:Parcels/src/parcels/_core/field.py
Lines 170 to 173 in b5c39b5
The result is cache misses as described here.
This PR resolves this problem by making igrid a property of a field that is set during
FieldSetconstruction byreconstruct_fields().Checklist
mainfor normal development,v3-supportfor v3 support)AI Disclosure