Skip to content

BUG: FutureWarning in distance_transform_cdt #17381

@martinResearch

Description

@martinResearch

Describe your issue.

Getting FutureWarning when using distance_transform_cdt with a metric that is a numpy array
FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison

In here

if metric in ['taxicab', 'cityblock', 'manhattan']:

we need to replace

    if metric in ['taxicab', 'cityblock', 'manhattan']:
        rank = input.ndima
        metric = generate_binary_structure(rank, 1)
    elif metric == 'chessboard':
        rank = input.ndim
        metric = generate_binary_structure(rank, rank)

by

    if isintance(metric,str) and metric in ['taxicab', 'cityblock', 'manhattan']:
        rank = input.ndima
        metric = generate_binary_structure(rank, 1)
    elif  isintance(metric,str) and metric == 'chessboard':
        rank = input.ndim
        metric = generate_binary_structure(rank, rank)

Reproducing Code Example

from scipy impoirt ndimage
import numpy as np
ndimage.distance_transform_cdt(np.zeros((5,5), dtype=bool), metric=np.ones((3,3), dtype=bool))

Error message

<string>:1: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison

SciPy/NumPy/Python version information

1.9.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.ndimage

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions