Description
Several xrspatial.hydro public functions accept a primary raster (validated correctly) plus a secondary xarray.DataArray argument that is never run through _validate_raster. Passing a non-DataArray, a 1-D DataArray, or a None for the secondary arg raises a confusing AttributeError from inside the implementation rather than a clean ValueError from the public API.
Affected:
| Function |
Validated |
Unvalidated arg |
watershed_d8 / watershed_dinf / watershed_mfd |
flow-direction |
pour_points |
snap_pour_point_d8 |
flow_accum |
pour_points |
flow_path_d8 / flow_path_dinf / flow_path_mfd |
flow-direction |
start_points |
stream_link_d8 / stream_link_dinf / stream_link_mfd |
flow-direction |
flow_accum |
stream_order_d8 / stream_order_dinf / stream_order_mfd |
flow-direction |
flow_accum |
Examples that should fail cleanly today but do not:
watershed_d8(fd, pour_points=None) -> AttributeError: 'NoneType' object has no attribute 'data'
flow_path_d8(fd, start_points=np.zeros(5)) -> AttributeError
stream_link_d8(fd, flow_accum=xr.DataArray(np.zeros(5))) -> IndexError from dims[-2]
Expected behavior
Each function calls _validate_raster on the secondary DataArray argument up front, mirroring how the primary raster is already validated. Bad input raises ValueError / TypeError with a clear message naming the offending parameter.
Proposed fix
Add _validate_raster(<arg>, func_name=..., name=<arg-name>) immediately after the existing _validate_raster call in each function listed above.
Description
Several
xrspatial.hydropublic functions accept a primary raster (validated correctly) plus a secondaryxarray.DataArrayargument that is never run through_validate_raster. Passing a non-DataArray, a 1-D DataArray, or aNonefor the secondary arg raises a confusingAttributeErrorfrom inside the implementation rather than a cleanValueErrorfrom the public API.Affected:
watershed_d8/watershed_dinf/watershed_mfdpour_pointssnap_pour_point_d8flow_accumpour_pointsflow_path_d8/flow_path_dinf/flow_path_mfdstart_pointsstream_link_d8/stream_link_dinf/stream_link_mfdflow_accumstream_order_d8/stream_order_dinf/stream_order_mfdflow_accumExamples that should fail cleanly today but do not:
watershed_d8(fd, pour_points=None)->AttributeError: 'NoneType' object has no attribute 'data'flow_path_d8(fd, start_points=np.zeros(5))->AttributeErrorstream_link_d8(fd, flow_accum=xr.DataArray(np.zeros(5)))->IndexErrorfromdims[-2]Expected behavior
Each function calls
_validate_rasteron the secondary DataArray argument up front, mirroring how the primary raster is already validated. Bad input raisesValueError/TypeErrorwith a clear message naming the offending parameter.Proposed fix
Add
_validate_raster(<arg>, func_name=..., name=<arg-name>)immediately after the existing_validate_rastercall in each function listed above.