Fix read_file for shapefiles without image_path/label columns (#997) #1242
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
Allow users to pass
image_pathandlabelarguments toread_file()when reading shapefiles that don't have these columns.Problem
When users have a shapefile without
image_pathorlabelcolumns,read_file()crashes with:Solution
Pass
image_pathargument toshapefile_to_annotations()- Modifiedutilities.pyto forward theimage_pathargument when reading shapefiles.Add warning when
image_pathis passed - Users see a warning confirming the value will be assigned to every row.Allow
labelargument - Removed blocking error for missing label column. Now defaults to "Unknown" if not provided.Write tests for shapefiles - Added 4 tests covering all scenarios.
Add documentation example - Added example in
docs/user_guide/01_Reading_data.mdwith argument table showing required vs optional parameters.Before & After
For shapefiles without
image_pathandlabelcolumns:image_pathargumentValueErrorimage_pathandlabelargumentsValueErrorFor shapefiles with
image_pathandlabelcolumns:image_pathargumentlabelargumentUsage Improvement
Previously (workaround):
This required two extra library imports (
osandgeopandas).Now:
No extra library imports needed. Here,
root_diris optional whenimage_pathis a full path.labelis optional too and defaults to "Unknown" when not provided.Related Issue(s)
Closes #997