Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin numpy<2 in ci_tests_legacy.yaml #3641

Merged
merged 4 commits into from
Nov 22, 2024
Merged

Pin numpy<2 in ci_tests_legacy.yaml #3641

merged 4 commits into from
Nov 22, 2024

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Nov 22, 2024

Description of proposed changes

The ci_test_legacy.yaml GitHub workflow has been failing since last month with a TypeError, e.g. at https://github.com/GenericMappingTools/pygmt/actions/runs/11450983970/job/31859442362#step:6:1474:

___________________ test_geopandas_plot3d_non_default_circle ___________________

args = (), kwargs = {}

    def wrapper(*args, **kwargs):
>       store.return_value[test_name] = obj(*args, **kwargs)

../../../../micromamba/envs/pygmt/lib/python3.10/site-packages/pytest_mpl/plugin.py:125: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../pygmt/tests/test_geopandas.py:145: in test_geopandas_plot3d_non_default_circle
    multipoint = shapely.geometry.MultiPoint([(0.5, 0.5, 0.5), (1.5, 1.5, 1.5)])
../../../../micromamba/envs/pygmt/lib/python3.10/site-packages/shapely/geometry/multipoint.py:62: in __new__
    return shapely.multipoints(subs)
../../../../micromamba/envs/pygmt/lib/python3.10/site-packages/shapely/decorators.py:77: in wrapped
    return func(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

geometries = array([<POINT Z (0.5 0.5 0.5)>, <POINT Z (1.5 1.5 1.5)>], dtype=object)
indices = None, out = None, kwargs = {}, typ = <GeometryType.MULTIPOINT: 4>

    @multithreading_enabled
    def multipoints(geometries, indices=None, out=None, **kwargs):
        """Create multipoints from arrays of points
    
        Parameters
        ----------
        geometries : array_like
            An array of points or coordinates (see points).
        indices : array_like, optional
            Indices into the target array where input geometries belong. If
            provided, both geometries and indices should be 1D and have matching
            sizes. Indices should be in increasing order. Missing indices result
            in a ValueError unless ``out`` is  provided, in which case the original
            value in ``out`` is kept.
        out : ndarray, optional
            An array (with dtype object) to output the geometries into.
        **kwargs
            See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
            Ignored if ``indices`` is provided.
    
        Examples
        --------
        Multipoints are constructed from points:
    
        >>> point_1 = points([1, 1])
        >>> point_2 = points([2, 2])
        >>> multipoints([point_1, point_2])
        <MULTIPOINT (1 1, 2 2)>
        >>> multipoints([[point_1, point_2], [point_2, None]]).tolist()
        [<MULTIPOINT (1 1, 2 2)>, <MULTIPOINT (2 2)>]
    
        Or from coordinates directly:
    
        >>> multipoints([[0, 0], [2, 2], [3, 3]])
        <MULTIPOINT (0 0, 2 2, 3 3)>
    
        Multiple multipoints of different sizes can be constructed efficiently using the
        ``indices`` keyword argument:
    
        >>> multipoints([point_1, point_2, point_2], indices=[0, 0, 1]).tolist()
        [<MULTIPOINT (1 1, 2 2)>, <MULTIPOINT (2 2)>]
    
        Missing input values (``None``) are ignored and may result in an
        empty multipoint:
    
        >>> multipoints([None])
        <MULTIPOINT EMPTY>
        >>> multipoints([point_1, None], indices=[0, 0]).tolist()
        [<MULTIPOINT (1 1)>]
        >>> multipoints([point_1, None], indices=[0, 1]).tolist()
        [<MULTIPOINT (1 1)>, <MULTIPOINT EMPTY>]
        """
        typ = GeometryType.MULTIPOINT
        geometries = np.asarray(geometries)
        if not isinstance(geometries, Geometry) and np.issubdtype(
            geometries.dtype, np.number
        ):
            geometries = points(geometries)
        if indices is None:
>           return lib.create_collection(geometries, typ, out=out, **kwargs)
E           TypeError: ufunc 'create_collection' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

The solution upstream at shapely shapely/shapely#2098 is to upgrade to shapely 2.0.6 to deal with the incompatibilty with numpy 2.1. But I think we should just test on numpy<2 since the legacy tests are meant to test old versions.

Also, I've cherry-picked commit 1263075 from #3639 here so that the terminal outputs for the legacy tests are colored (as per #3330).

Fixes #

Preview:

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash command is:

  • /format: automatically format and lint the code

To fix `TypeError: ufunc 'create_collection' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''`. Xref shapely/shapely#2098
@weiji14 weiji14 added the maintenance Boring but important stuff for the core devs label Nov 22, 2024
@weiji14 weiji14 self-assigned this Nov 22, 2024
@weiji14
Copy link
Member Author

weiji14 commented Nov 22, 2024

There is one more test failure at https://github.com/GenericMappingTools/pygmt/actions/runs/11964508602/job/33356945576?pr=3641#step:6:940:

_______________ [doctest] pygmt.datasets.tile_map.load_tile_map ________________
118     >>> raster.sizes
119     Frozen({'band': 3, 'y': 256, 'x': 512})
120     >>> raster.coords  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
121     Coordinates:
122       * band         (band) uint8... 1 2 3
123       * y            (y) float64... -7.081e-10 -7.858e+04 ... -1.996e+07 -2.004e+07
124       * x            (x) float64... -2.004e+07 -1.996e+07 ... 1.996e+07 2.004e+07
125         spatial_ref  int... 0
126     >>> # CRS is set only if rioxarray is available
127     >>> if hasattr(raster, "rio"):
Expected:
    CRS.from_wkt(...)
Got:
    CRS.from_epsg(3857)
/home/runner/work/pygmt/pygmt/pygmt/datasets/tile_map.py:127: DocTestFailure

This is caused by the changes made in #3575/#3576, but not sure if we want to pin to a lower version of rasterio. Edit: see #3642.

@weiji14 weiji14 marked this pull request as ready for review November 22, 2024 01:30
@weiji14 weiji14 merged commit b7f0627 into main Nov 22, 2024
7 checks passed
@weiji14 weiji14 deleted the legacy/pin_numpy_lt2 branch November 22, 2024 01:42
@weiji14 weiji14 added this to the 0.14.0 milestone Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants