You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ufunc 'create_collection' not supported for the input types #2098
This is a recent issue identified using nightly numpy binary wheels with the main branch of shapely.
The error looks like this:
=========================== test session starts ============================
platform linux -- Python 3.10.12, pytest-8.2.2, pluggy-1.5.0
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/mtoews/src/shapely/shapely
configfile: setup.cfg
plugins: syrupy-4.6.1, anyio-4.4.0, dotenv-0.5.2, flaky-3.8.1, hypothesis-6.108.5, cov-5.0.0, xdist-3.6.1, benchmark-4.0.0
collected 9 items / 1 error
================================== ERRORS ==================================
__________ ERROR collecting shapely/tests/geometry/test_coords.py __________
shapely/tests/geometry/test_coords.py:5: in <module>
from shapely.tests.common import line_string, line_string_z, point, point_z
shapely/tests/common.py:26: in <module>
multi_point = shapely.MultiPoint([(0, 0), (1, 2)])
shapely/geometry/multipoint.py:62: in __new__
return shapely.multipoints(subs)
shapely/decorators.py:77: in wrapped
return func(*args, **kwargs)
shapely/creation.py:433: in multipoints
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''
========================= short test summary info ==========================
ERROR shapely/tests/geometry/test_coords.py - TypeError: ufunc 'create_collection' not supported for the input types,...
!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!
============================= 1 error in 0.41s =============================
where the last line would normally return <MULTIPOINT ((1 2), (3 4))> before the referenced numpy commit or the error:
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''
You can support the dfault int in C mainly. It's a pretty niche change and a warning is hard, because it is rare that it will trigger any change. Since most ufuncs will support the default integer explicitly.
@mwtoews thanks for the investigation and @seberg for the explanation.
I was quickly checking in which places we should need such a cast, and opened a PR for that -> #2099
We do have a set of other enums for modelling parameter options, and in all those cases it seems we were already casting the enum to an int. For example:
(although I see we consistently use np.intc(..) for the casting while in the PR I just opened I used a python integer int(..), will change that for consistency)
Sounds right. Is this a big enough problem to worry about delaying things in NumPy (also since 2.1 is probably be going to be relatively soon for Python 3.13 support).
Yeah, on conda-forge the numpy 2.0 support was added later, and for packages built before that, conda-forge automatically ads a numpy<2 constraint (even though shapely itself didn't have that).
So in practice, it seems that indeed only shapely 2.0.5 could be patched with a numpy<2.1 (shapely 2.0.4 still has a numpy<2 upper pin). I suppose opening a PR for that in https://github.com/conda-forge/conda-forge-repodata-patches-feedstock is welcome (I don't have any permissions their either, it will need to be reviewed by a core conda-forge team member anyway)
Activity
mwtoews commentedon Jul 28, 2024
Here is a short reproducer:
where the last line would normally return
<MULTIPOINT ((1 2), (3 4))>before the referenced numpy commit or the error:But also, this works:
so there is maybe unsafe casting from the IntEnum
GeometryType.MULTIPOINTto the int 4 (NPY_INT)?Other ufunc info for
shapely.lib.create_collection:seberg commentedon Jul 28, 2024
Makes sense, I guess intenums may be int subclasses, is it a problem to cast to
int()to make iticompatible (rather thanint64/intp?)mwtoews commentedon Jul 28, 2024
Thanks @seberg for taking a look; a few follow-up items/questions:
int(GeometryType.MULTIPOINT)before sending to the ufunc is a possible change we can make.np.sqrt(GeometryType.MULTIPOINT)cast the enum to float64 without error? Is there a change that we could make on the C-side?np.result_type(GeometryType.MULTIPOINT)returndtype('int64').seberg commentedon Jul 29, 2024
You can support the dfault int in C mainly. It's a pretty niche change and a warning is hard, because it is rare that it will trigger any change. Since most ufuncs will support the default integer explicitly.
jorisvandenbossche commentedon Jul 29, 2024
@mwtoews thanks for the investigation and @seberg for the explanation.
I was quickly checking in which places we should need such a cast, and opened a PR for that -> #2099
We do have a set of other enums for modelling parameter options, and in all those cases it seems we were already casting the enum to an int. For example:
shapely/shapely/_geometry.py
Lines 842 to 852 in 9a8bf73
or the various buffer arguments:
shapely/shapely/constructive.py
Lines 181 to 190 in 9a8bf73
(although I see we consistently use
np.intc(..)for the casting while in the PR I just opened I used a python integerint(..), will change that for consistency)seberg commentedon Jul 29, 2024
Sounds right. Is this a big enough problem to worry about delaying things in NumPy (also since 2.1 is probably be going to be relatively soon for Python 3.13 support).
jorisvandenbossche commentedon Jul 29, 2024
I don't think so, we can always include this small fix in another 2.0.x release
AlessandroMondin commentedon Aug 19, 2024
Same problem with numpy 2.1.0 (released yesterday)
ethan-moss commentedon Aug 19, 2024
@AlessandroMondin - as a short-term solution, reverting back to numpy 2.0.1 has at least patched the issue for me. Hope that helps!
ci(test_environment.yaml): pin numpy<2.1 for now, to avoid this shape…
chore: ceil numpy to avoid shapely/shapely#2098
chore: ceil numpy to avoid shapely/shapely#2098
chore: ceil numpy to avoid shapely/shapely#2098
jorisvandenbossche commentedon Aug 19, 2024
Shapely 2.0.6 is released that includes the fix (it's on pypi, conda-forge can still take a few hours)
added numpy<2.0.1 as requirement since it breaks the dissolve in util…
ci(test_environment.yaml): pin numpy<2.1 for now, to avoid this shape…
ChrisBarker-NOAA commentedon Sep 4, 2024
I jsut found this issue with:
all conda-forge builds.
updating to shapely 2.0.6 fixed it -- nice work!
But maybe the 2.0.5 builds on conda-forge should be marked as broken?
https://github.com/conda-forge/admin-requests?tab=readme-ov-file#mark-packages-as-broken-on-conda-forge
martinfleis commentedon Sep 4, 2024
They're not broken, just not compatible with the latest numpy. Following this logic, we would have to mark as broken all releases prior to 2.0.6.
ChrisBarker-NOAA commentedon Sep 5, 2024
Got it -- but the dependencies are wrong, yes?
That can be updated with:
https://prefix.dev/blog/repodata_patching
https://github.com/conda-forge/conda-forge-repodata-patches-feedstock
I think shapely 2.0.5 should have:
rather than:
I could help with this if need be, though I don't have permissions on the feedstock, so maybe not?
jorisvandenbossche commentedon Sep 5, 2024
Yeah, on conda-forge the numpy 2.0 support was added later, and for packages built before that, conda-forge automatically ads a numpy<2 constraint (even though shapely itself didn't have that).
So in practice, it seems that indeed only shapely 2.0.5 could be patched with a numpy<2.1 (shapely 2.0.4 still has a numpy<2 upper pin). I suppose opening a PR for that in https://github.com/conda-forge/conda-forge-repodata-patches-feedstock is welcome (I don't have any permissions their either, it will need to be reviewed by a core conda-forge team member anyway)
ci(test_environment.yaml): pin numpy<2.1 for now, to avoid this shape…
Pin numpy<2 in ci_tests_legacy.yaml
Pin numpy<2 in ci_tests_legacy.yaml (#3641)
ci(test_environment.yaml): pin numpy<2.1 for now, to avoid this shape…
added numpy<2.0.1 as requirement since it breaks the dissolve in util…