Skip to content

Failures with numpy 1.20.0rc1 #268

@jorisvandenbossche

Description

@jorisvandenbossche

See eg https://github.com/pygeos/pygeos/runs/1519984556

 ____________________________ test_from_shapely_arr _____________________________

    @mock.patch("pygeos.io.ShapelyGeometry", ShapelyGeometryMock)
    @mock.patch("pygeos.io.shapely_geos_version", pygeos.geos_capi_version_string)
    def test_from_shapely_arr():
>       actual = pygeos.from_shapely([ShapelyGeometryMock(point), None])

pygeos/test/test_io.py:341: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pygeos/io.py:243: in from_shapely
    arr = np.asarray(geometry, dtype=object)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = [<pygeos.test.test_io.ShapelyGeometryMock object at 0x7f65862e0190>, None]
dtype = <class 'object'>, order = None

    @set_array_function_like_doc
    @set_module('numpy')
    def asarray(a, dtype=None, order=None, *, like=None):
        """
        ....
        """
        if like is not None:
            return _asarray_with_like(a, dtype=dtype, order=order, like=like)
    
>       return array(a, dtype, copy=False, order=order)
E       ValueError: Invalid __array_interface__ value, must be a dict

This ShapelyGeometryMock is defined as

class ShapelyGeometryMock:
def __init__(self, g):
self.g = g
self.__geom__ = g._ptr if hasattr(g, "_ptr") else g
def __array_interface__(self):
# this should not be called
raise NotImplementedError()

but so apparently numpy now calls the __array_interface__ on individual objects in a list in np.asarray(..).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions