Skip to content

Fix minkowski distanced invocation for SciPy >= 1.18 - #8157

Merged
blink1073 merged 3 commits into
scikit-image:mainfrom
stefanv:minkowski-nightlies
May 13, 2026
Merged

blink1073 merged 3 commits into
scikit-image:mainfrom
stefanv:minkowski-nightlies

Conversation

@stefanv

@stefanv stefanv commented May 11, 2026 •

Copy link
Copy Markdown
Member

SciPy now raises a warning for spatial.minkowski_distance, need to use spatial.distance.minkowski instead.

Without this fix, we don't build nightlies.

@stefanv stefanv added the 🔧 type: Maintenance Refactoring and maintenance of internals label May 11, 2026
@greptile-apps

greptile-apps Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "Fix minkowski distanced invocation for S..." | Re-trigger Greptile

Comment thread src/skimage/measure/fit.py Resolved
@greptile-apps

greptile-apps Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "Explicitly check scipy version" | Re-trigger Greptile

Comment on lines +627 to +631
# Can remove once SciPy 1.18 is the default
if version.parse(scipy.__version__) >= version.parse('1.18.0dev0'):
distances = scipy.spatial.distance.minkowski(center, data)
else:
distances = scipy.spatial.minkowski_distance(center, data)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 scipy.spatial.distance.minkowski(u, v) accepts two 1-D arrays and returns a single scalar distance. The old scipy.spatial.minkowski_distance(center, data) accepted (K,) + (N, K) inputs and returned an (N,) array of per-point distances. Passing center (shape (2,)) and data (shape (N, 2)) to the new function will either raise a shape error or return a scalar, making np.mean(distances**2) a scalar and r the wrong value. A broadcast-safe replacement is np.linalg.norm(data - center, axis=1), which is dependency-free and always correct.

Suggested change
# Can remove once SciPy 1.18 is the default
if version.parse(scipy.__version__) >= version.parse('1.18.0dev0'):
distances = scipy.spatial.distance.minkowski(center, data)
else:
distances = scipy.spatial.minkowski_distance(center, data)
distances = np.linalg.norm(data - center, axis=1)

@greptile-apps

greptile-apps Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Reviews (3): Last reviewed commit: "Merge branch 'main' into minkowski-night..." | Re-trigger Greptile

@stefanv

stefanv commented May 11, 2026

Copy link
Copy Markdown
Member Author

macOS failure is with wrap: unrelated

@blink1073

Copy link
Copy Markdown
Contributor

I have the greptile suggested fix in #8156

@stefanv

stefanv commented May 12, 2026

Copy link
Copy Markdown
Member Author

This is more minimal, but I'm okay with either. Do you have a preference?

@blink1073

Copy link
Copy Markdown
Contributor

The problem with the new minkowski function is that it only operates on 1-D arrays. If we were using it for another p value I think it would have been a good idea to push back on the deprecation, but I think using linalg.norm is the way to go for computational efficiency.

@stefanv

stefanv commented May 12, 2026

Copy link
Copy Markdown
Member Author

The problem with the new minkowski function is that it only operates on 1-D arrays.

I think SciPy addressed this in scipy/scipy#24780, which is why the test suite is passing on this PR.

@blink1073

Copy link
Copy Markdown
Contributor

I think SciPy addressed this in scipy/scipy#24780, which is why the test suite is passing on this PR.

Great! Then it definitely makes sense to have the version guard.

@blink1073

Copy link
Copy Markdown
Contributor

Let's merge this and see if there is still the other failure I saw while working on #8156

@blink1073
blink1073 merged commit 3f8abbe into scikit-image:main May 13, 2026
25 of 26 checks passed
@stefanv stefanv added this to the 0.27 milestone May 13, 2026
matthew-brett added a commit that referenced this pull request May 19, 2026
* origin/main:
  Use standard C99 static inline instead of `__inline` (#8159)
  Fix structural_similarity win_size / gaussian_weights conflict (#8162)
  Unwrap seed refactor (#8142)
  ci: Remove llvm build and add ccache support on windows (#8164)
  Document warn_external in contributing guide (#8163)
  CI: Fix emscripten dependencies and clean up wheel test commands (#8147)
  Test only changed subpackages (#8103)
  Fix nightlies: update deprecated scipy call, fix underdetermined test
  Fix minkowski distanced invocation for SciPy >= 1.18 (#8157)
  Port `structural_similarly` to ski2 (#8104)
  make spin build requirement a lower bound (#8158)
matthew-brett added a commit to matthew-brett/scikit-image that referenced this pull request May 21, 2026
* origin/main: (254 commits)
  Refactor, document migration utilities (scikit-image#8184)
  ci: improve handling of pr labels (scikit-image#8169)
  Doctest migration in PRs & on all platforms (scikit-image#8141)
  Update SKIP 4 (import hierarchy, backporting, testing) (scikit-image#8097)
  One page per function / class in HTML docs for skimage2 (scikit-image#8154)
  Pin minimum pytest to 9 (scikit-image#8174)
  docs: make source install instructions more discoverable and add build requirements to top level requirements file (scikit-image#8165)
  Drop `--maxfail=5` from local pytest config (scikit-image#8170)
  Use standard C99 static inline instead of `__inline` (scikit-image#8159)
  Fix structural_similarity win_size / gaussian_weights conflict (scikit-image#8162)
  Unwrap seed refactor (scikit-image#8142)
  ci: Remove llvm build and add ccache support on windows (scikit-image#8164)
  Document warn_external in contributing guide (scikit-image#8163)
  CI: Fix emscripten dependencies and clean up wheel test commands (scikit-image#8147)
  Test only changed subpackages (scikit-image#8103)
  Fix nightlies: update deprecated scipy call, fix underdetermined test
  Fix minkowski distanced invocation for SciPy >= 1.18 (scikit-image#8157)
  Port `structural_similarly` to ski2 (scikit-image#8104)
  make spin build requirement a lower bound (scikit-image#8158)
  Drop Python 3.11 Support (scikit-image#8153)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔧 type: Maintenance Refactoring and maintenance of internals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants