You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains 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
Possible Bug:
Ensure that the use of datetime.datetime.now(datetime.UTC) is correctly implemented. The correct usage should be datetime.datetime.now(datetime.timezone.utc).
Data Conversion:
Verify that the use of .item() for converting numpy and xarray data types to Python built-in types does not lead to loss of precision or other unintended side effects, especially in large datasets.
Data Structure Conversion:
Ensure that the conversion of numpy arrays to lists using .tolist() in the Jinja2 templates does not impact performance or expected behavior, particularly with large arrays.
Why: The suggestion correctly identifies the deprecation of datetime.UTC and provides a compatible alternative, improving code compatibility with Python 3.9 and later versions.
10
Possible bug
Add error handling for potential None values in min/max calculations
Add error handling for cases where array[dim].min() or array[dim].max() might return NaN or None, which would cause item() to fail.
-dim: np.linspace(array[dim].min().item(), array[dim].max().item(), ni)+dim: np.linspace(array[dim].min().item() if array[dim].min() is not None else 0, array[dim].max().item() if array[dim].max() is not None else 0, ni)
Suggestion importance[1-10]: 8
Why: The suggestion addresses a potential bug by adding error handling for None values, which could cause the item() method to fail, thus improving the robustness of the code.
8
Add checks to ensure region.pmin and region.pmax are iterable before converting to list
Ensure that region.pmin and region.pmax are always lists or arrays before calling tolist() to avoid potential errors if the properties are not iterable.
Why: The suggestion improves code robustness by ensuring region.pmin and region.pmax are iterable before calling tolist(), preventing potential runtime errors.
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.
User description
PR Type
Enhancement, Bug fix
Description
datetime
usage to handle deprecation ofutcnow()
in Python 3.12..item()
to convert xarray and numpy values to Python built-in types.mesh.n
,region.pmin
, andregion.pmax
to lists usingtolist()
method in Jinja2 templates.Changes walkthrough 📝
hdf5.py
Update datetime usage to handle deprecation in Python 3.12
discretisedfield/io/hdf5.py
utcnow
tonow
withdatetime.UTC
to handle deprecation inPython 3.12.
hv.py
Ensure compatibility with xarray in resampling function
discretisedfield/plotting/hv.py
.item()
to convert xarray to Python built-in type before usinglinspace
.tools.py
Convert numpy values to Python types in count_bps function
discretisedfield/tools/tools.py
.item()
to convert numpy values to Python built-in types.mesh.jinja2
Convert mesh.n to list in mesh template
discretisedfield/html/templates/mesh.jinja2
mesh.n
to list usingtolist()
method.region.jinja2
Convert region.pmin and region.pmax to list in region template
discretisedfield/html/templates/region.jinja2
region.pmin
andregion.pmax
to list usingtolist()
method.