question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Latest numpy 1.21.0 release causes "Unknown ufunc mode" for set_precision

See original GitHub issue

Seen on a PR, but I think it’s not related to the changes in that PR but to the bump of the numpy version, which just had a 1.21.0 release (https://numpy.org/doc/stable/release/1.21.0-notes.html#compatibility-notes):

 =================================== FAILURES ===================================
______________________________ test_get_precision ______________________________

    @pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6")
    def test_get_precision():
        geometries = all_types + (point_z, empty_point, empty_line_string, empty_polygon)
        # default is 0
        actual = pygeos.get_precision(geometries).tolist()
        assert actual == [0] * len(geometries)
    
>       geometry = pygeos.set_precision(geometries, 1)

pygeos/test/test_geometry.py:430: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pygeos/decorators.py:70: in wrapped
    return func(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

geometry = (<pygeos.Geometry POINT (2 3)>, <pygeos.Geometry LINESTRING (0 0, 1 0, 1 1)>, <pygeos.Geometry LINEARRING (0 0, 1 0, 1...0, 2 0, 2 2, 0 2, 0 0))>, <pygeos.Geometry MULTIPOINT (0 0, 1 2)>, <pygeos.Geometry MULTILINESTRING ((0 0, 1 2))>, ...)
grid_size = 1, preserve_topology = False, kwargs = {}

    @requires_geos("3.6.0")
    @multithreading_enabled
    def set_precision(geometry, grid_size, preserve_topology=False, **kwargs):
        """Returns geometry with the precision set to a precision grid size.
    
        By default, geometries use double precision coordinates (grid_size = 0).
    
        Coordinates will be rounded if a precision grid is less precise than the
        input geometry. Duplicated vertices will be dropped from lines and
        polygons for grid sizes greater than 0. Line and polygon geometries may
        collapse to empty geometries if all vertices are closer together than
        grid_size. Z values, if present, will not be modified.
    
        Note: subsequent operations will always be performed in the precision of
        the geometry with higher precision (smaller "grid_size"). That same
        precision will be attached to the operation outputs.
    
        Also note: input geometries should be geometrically valid; unexpected
        results may occur if input geometries are not.
    
        Returns None if geometry is None.
    
        Parameters
        ----------
        geometry : Geometry or array_like
        grid_size : float
            Precision grid size. If 0, will use double precision (will not modify
            geometry if precision grid size was not previously set). If this
            value is more precise than input geometry, the input geometry will
            not be modified.
        preserve_topology : bool, default False
            If True, will attempt to preserve the topology of a geometry after
            rounding coordinates.
        **kwargs
            For other keyword-only arguments, see the
            `NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.
    
        See also
        --------
        get_precision
    
        Examples
        --------
        >>> set_precision(Geometry("POINT (0.9 0.9)"), 1.0)
        <pygeos.Geometry POINT (1 1)>
        >>> set_precision(Geometry("POINT (0.9 0.9 0.9)"), 1.0)
        <pygeos.Geometry POINT Z (1 1 0.9)>
        >>> set_precision(Geometry("LINESTRING (0 0, 0 0.1, 0 1, 1 1)"), 1.0)
        <pygeos.Geometry LINESTRING (0 0, 0 1, 1 1)>
        >>> set_precision(None, 1.0) is None
        True
        """
    
>       return lib.set_precision(geometry, grid_size, preserve_topology, **kwargs)
E       NotImplementedError: Unknown ufunc mode with args[0]=0x7f91f8161790, args[N]=0x1, steps[0]=8, steps[N]=0, dimensions[0]=13.

pygeos/geometry.py:737: NotImplementedError

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Jun 29, 2021

OK, so actually for the failing test case, it doesn’t seem something changed with the latest numpy version in the steps. So because of the out-of-bounds index bug, we probably just got undefined behaviour. This is fixed with #367.


If I add a print statement in the CHECK_NO_INPLACE_OUTPUT macro, we get the following for an older and latest version of numpy. After correcting the index, for set_precision with an array as input and output, we get the same steps (it’s for the ufunc that receives a scalar as input that the steps of the output changed from 0 to 8, but that doesn’t matter for us, it’s also a single element output)

In [1]: from pygeos.test.common import all_types, point_z, empty_point, empty_line_string, empty_polygon
ufunc mode with args[0]=0x55ae3750ad00, args[N]=0x55ae3750ab30, steps[0]=0, steps[N]=0, dimensions[0]=1.

In [2]: geometries = all_types + (point_z, empty_point, empty_line_string, empty_polygon)

In [3]: import pygeos

In [4]: pygeos.set_precision(geometries, 1)
ufunc mode with args[0]=0x55ae375283a0, args[N]=0x55ae3753bce0, steps[0]=8, steps[N]=8, dimensions[0]=13.
Out[4]: 
array([<pygeos.Geometry POINT (2 3)>, ...

In [5]: np.__version__
Out[5]: '1.18.4'
In [1]: from pygeos.test.common import all_types, point_z, empty_point, empty_line_string, empty_polygon
ufunc mode with args[0]=0x55d879227920, args[N]=0x55d879270b50, steps[0]=0, steps[N]=8, dimensions[0]=1.

In [2]: geometries = all_types + (point_z, empty_point, empty_line_string, empty_polygon)

In [3]: import pygeos

In [4]: pygeos.set_precision(geometries, 1)
ufunc mode with args[0]=0x55d878e9c860, args[N]=0x55d878df19c0, steps[0]=8, steps[N]=8, dimensions[0]=13.
Out[4]: 
array([<pygeos.Geometry POINT (2 3)>, ...

In [5]: np.__version__
Out[5]: '1.21.0'
0reactions
sebergcommented, Jun 28, 2021

OK, let me know if you find anything, it probably is related to the contiguity flags not matching somehow. The problem with continuity may just be that the scalar is both Fortran- and C-order contiguous, and the other argument(s) are only C- or only F-order contiguous…

I expect our change is good, but I may be able to undo it in the release branch if it gives you a lot of headaches.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NumPy 1.21.0 Release Notes
It was deprecated in NumPy 1.19. Users should call the ufunc directly using the Python API. The function PyUFunc_SetUsesArraysAsData has been disabled. It...
Read more >
python - Installing numpy 1.21.0 or earlier - Stack Overflow
Solved this by downgrading to Python 3.6 (completely uninstalling Python 3.10) and using this to install Pandas 1.19.5 via pip.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found