Handle empty sequences in convert_ras_hdf_value#101
Open
arpitjain099 wants to merge 1 commit into
Open
Conversation
An empty list, tuple, or numpy array fell through the len(value) > 1 check into the single-element branch and indexed value[0], raising IndexError. Return None for the empty case, consistent with how the function already maps absent values such as NaN to None, and add a test covering empty list, tuple, and array inputs. Signed-off-by: Arpit Jain <arpitjain099@gmail.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.
convert_ras_hdf_value()insrc/rashdf/utils.pyraisesIndexErrorwhen it ishanded an empty sequence. The list/tuple/ndarray branch only distinguishes
len(value) > 1from everything else, so an empty value falls into thesingle-element
elsebranch and indexesvalue[0]:An empty array is easy to hit when an HDF attribute or dataset carries no
elements, and the resulting
IndexErroris harder to trace back than a cleanreturn. This adds an explicit
len(value) == 0case that returnsNone, whichmatches how the function already maps absent values (NaN becomes
None) andstays inside the declared return type.
Verification with pytest on the affected test:
tests/test_utils.py::test_convert_ras_hdf_valuefails withIndexError: list index out of rangeatsrc/rashdf/utils.py:295.tests/test_utils.pymodule is green(6 passed).
The test adds coverage for the empty list, tuple, and numpy array inputs.
I hit some unrelated failures in
test_geom.pyandtest_plan.pyin my localenvironment, but they reproduce on a clean checkout of
mainas well (they looklike geopandas/zarr version differences), so they are not related to this
change.