Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pygeoprocessing.get_gis_type should raise an exception if gdal can't open the file #244

Closed
phargogh opened this issue Mar 3, 2022 · 3 comments · Fixed by #289
Closed
Assignees
Labels
enhancement New feature or request in progress Working on it!
Milestone

Comments

@phargogh
Copy link
Member

phargogh commented Mar 3, 2022

Throughout pygeoprocessing, we do some basic checking for the case where gdal can't open up a dataset. get_raster_info and get_vector_info both do this, and it's reasonable to expect that get_gis_type would also do this.

@phargogh phargogh added the bug Something isn't working label Mar 3, 2022
@phargogh phargogh changed the title pygeoprocessing.get_gis_vector should raise an exception if gdal can't open the file pygeoprocessing.get_gis_type should raise an exception if gdal can't open the file Mar 3, 2022
@phargogh phargogh added this to the 2.3.5 milestone Dec 2, 2022
@dcdenu4 dcdenu4 self-assigned this Dec 2, 2022
@dcdenu4
Copy link
Member

dcdenu4 commented Dec 2, 2022

Hey @phargogh I was just looking at this and it appears that get_gis_type is designed to return pygeoprocessing.UNKNOWN_TYPE if gdal can not open a file as a raster or vector. Are you proposing that instead of that the function should raise a ValueError like get_raster_info and get_vector_info do?

Internally we use get_gis_type only once in stitch_rasters.

@dcdenu4 dcdenu4 added the in progress Working on it! label Dec 2, 2022
@dcdenu4
Copy link
Member

dcdenu4 commented Dec 2, 2022

Looks like the following InVEST models also call this function:

  • CV
  • HQ
  • HRA

@phargogh
Copy link
Member Author

phargogh commented Dec 2, 2022

Yes, I am proposing that if the raster cannot be opened, it should raise a ValueError consistent with how get_raster_info, get_vector_info and other functions in pygeoprocessing behave. My rationale before was that this behavior is inconsistent with the rest of pygroprocessing, where if we can't open a file with GDAL, we raise an exception. But after looking at it again, I think there's another more subtle implication of the current implementation: files that exist but cannot be opened by GDAL are deemed to have a GIS type of pygeoprocessing.UNKNOWN_TYPE. So if someone, say, tries to get the GIS type of a Microsoft Word file, it has an 'UNKNOWN' gis type? I feel like that should be an exception, not a valid return value. Pygeoprocessing only works with GIS files that GDAL supports, so if we can't open it, I think that should be an error.

But this is also a notable behavioral change, and so we might want to put it off until a minor release, which is totally fine by me.

@dcdenu4 dcdenu4 added enhancement New feature or request and removed bug Something isn't working labels Dec 2, 2022
dcdenu4 added a commit to dcdenu4/pygeoprocessing that referenced this issue Dec 13, 2022
dcdenu4 added a commit to dcdenu4/pygeoprocessing that referenced this issue Dec 13, 2022
dcdenu4 added a commit to dcdenu4/pygeoprocessing that referenced this issue Dec 13, 2022
dcdenu4 added a commit to dcdenu4/pygeoprocessing that referenced this issue Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in progress Working on it!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants