Type()-checking for np.ndarray is overly restrictive to subclasses
Closed this issue · 2 comments
pkla commented
Problem: In hausdorff.hausdorff_distance
, the first assertion, that type(XA) is np.ndarray and type(XB) is np.ndarray
, is overly restrictive as it disallows sub-classes of numpy.ndarray
. For example, a common use-case is to call this function on the points of a PyVista mesh, which are stored in a pyvista.pyvista_ndarray
. This object subclasses from numpy.ndarray
and is functionally identical but this function raises an assertion error if an instance is passed in.
py-hausdorff/hausdorff/hausdorff.py
Lines 39 to 40 in cf13865
Steps to reproduce: Create a subclass of numpy.ndarray
and pass an instance into hausdorff.hausdorff_distance
.
import numpy as np
from hausdorff import hausdorff_distance
class my_ndarray(np.ndarray): pass
a = my_ndarray(np.array([5, 2]))
hausdorff_distance(a, a) # raises AssertionError
mavillan commented
Already merged it, thanks for contributing!