Fix index parsing in mpas_to_xdmf tool#635
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the _parse_indices function to explicitly handle slice notation by splitting the index string into up to three parts, padding missing values, and applying defaults for start, stop, and step.
- Replace one-liner list comprehension with explicit parsing for slice support
- Preserve comma-separated index behavior unchanged
Comments suppressed due to low confidence (2)
conda_package/mpas_tools/viz/mpas_to_xdmf/io.py:300
- Update the function docstring to describe the new slice notation support (
start:stop:stepsemantics) and default behaviors when parts are omitted.
def _parse_indices(index_string, dim_size):
conda_package/mpas_tools/viz/mpas_to_xdmf/io.py:312
- Add unit tests for
_parse_indicescovering edge cases like ':', '5:', ':10', '::2', and invalid formats to ensure the new parsing logic works as expected.
return list(range(start, stop, step))
Collaborator
Author
TestingI was able to extract |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
This pull request focuses on improving the robustness of the
_parse_indicesfunction and significantly expanding the test coverage for the MPAS-to-XDMF conversion functionality. Key changes include handling edge cases in index parsing, adding validation, and introducing comprehensive unit tests for various scenarios.Enhancements to
_parse_indicesfunction:Expanded test coverage:
_parse_indicesto validate both valid and invalid cases, including mixed slice/list formats, empty strings, and invalid strings.main) with simulated arguments and user input, verifying the creation of expected output files.