Conversation
surface_distance, surface_allocation and surface_direction declared target_values: list = [] while proximity, allocation, direction and cost_distance use None and normalize to [] in the body. Passing target_values=None (common when wrapper code threads an optional arg through) reached np.asarray(None) and failed before the numba kernel. Change the three signatures to None and add the sibling 'if target_values is None: target_values = []' guard in the shared _compute dispatcher. [] and None both mean 'every non-zero finite pixel is a source', so callers passing an explicit list are unaffected. Also removes the mutable default argument the siblings already avoid.
|
Thanks for flagging — on comparing, #3746 is functionally the same fix as #3718 (same three signatures, same |
|
@shaikn6 cool cool, thanks for the contribution. I could help guide you a bit to other areas if youre interested in other contributions. Any existing tools (or new tools) you'd be interested in working on? |
|
Appreciate it — yes, interested. I've mostly been running |
Fixes #3712
Proposed Changes
surface_distance,surface_allocation,surface_directionnow accepttarget_values=None(the value wrapper code passes when its own optional arg is unset), matchingproximity/allocation/direction/cost_distance.target_values: list = []totarget_values: list = Noneand added the siblingif target_values is None: target_values = []guard in the shared_computedispatcher.test_target_values_none_matches_empty) parametrized over all three functions.Why / evidence
The proximity trio and
cost_distanceall declaretarget_values: list = Noneand normalize to[]in the body. The threesurface_*functions declaredtarget_values: list = []with noNoneguard, sotarget_values=Nonefell through tonp.asarray(None, dtype=np.float64)(a 0-d array) and blew up before the numba kernel. On numpy 2.3 it surfaces as the existingValueError: target_values must be a 1-D sequence; the issue reports a ~40-line numba TypingError on older numpy. Either way it is broken.[]as a default is also the mutable-default anti-pattern the siblings already avoid.Confirmed with the reproduction from #3712 on this checkout: pre-fix,
surface_distance/allocation/direction(target_values=None)raise while the other four return normally; post-fix all seven succeed.Change
[]andNoneboth mean "treat every non-zero finite pixel as a source", so callers passing an explicit list are unaffected and callers passingNonego from a traceback to working code. No parameter renamed, no accepted input changes meaning, so no deprecation shim is needed.Note:
balanced_allocationcarries the sametarget_values: list = []default (flagged in #3712 as out of scope) and is left untouched here.Verified
flake8 / isort: no new violations introduced by this change (the pre-existing
surface_distance.pyisort drift is tracked separately in #3710).