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

[Bug]: Creation of Geometry objects from other geometry objects not working #10

Closed
1 task done
arpit15 opened this issue Sep 13, 2024 · 5 comments · Fixed by #11
Closed
1 task done

[Bug]: Creation of Geometry objects from other geometry objects not working #10

arpit15 opened this issue Sep 13, 2024 · 5 comments · Fixed by #11
Assignees
Labels
bug Something isn't working

Comments

@arpit15
Copy link

arpit15 commented Sep 13, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

Creation of a class containing annotated MultiPolygon fails with a list of Polygon with validation error. Hopefully this behavior could be supported by changing validation logic in GeometryField

Error

Traceback (most recent call last):
  File "/home/username/coding_bits/pydantic_checks/pydantic_checks/check_shapely.py", line 33, in <module>
    obj = MyClass(polys=[Polygon(shell=((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)))])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/username/coding_bits/pydantic_checks/.venv/lib/python3.11/site-packages/pydantic/_internal/_dataclasses.py", line 134, in __init__
    s.__pydantic_validator__.validate_python(ArgsKwargs(args, kwargs), self_instance=s)
pydantic_core._pydantic_core.ValidationError: 1 validation error for MyClass
polys
  Value error, Supplied string is not a valid WKT-string [type=value_error, input_value=[<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>], input_type=list]
    For further information visit https://errors.pydantic.dev/2.5/v/value_error

Example Code

from shapely import MultiPolygon, Polygon
from pydantic_shapely import GeometryField
from pydantic.dataclasses import dataclass

@dataclass
class MyClass:
    polys: Annotated[MultiPolygon, GeometryField()]

mpoly = MultiPolygon([Polygon(shell=((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)))])
assert isinstance(mpoly, MultiPolygon)

obj = MyClass(polys=MultiPolygon([
    (
    ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)),
    [((0.1,0.1), (0.1,0.2), (0.2,0.2), (0.2,0.1))]
    )
]))

obj = MyClass(polys=[Polygon(shell=((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)))])


### Python, Pydantic, Shapely & OS Version

```Text
Pydantic-shapely version: 1.0.0a2
Shapely version: 2.0.6
             pydantic version: 2.5.3
        pydantic-core version: 2.14.6
          pydantic-core build: profile=release pgo=true
                 install path: /home/username/coding_bits/pydantic_checks/.venv/lib/python3.11/site-packages/pydantic
               python version: 3.11.4 (main, Aug 14 2023, 05:19:15) [GCC 7.5.0]
                     platform: Linux-6.8.0-40-generic-x86_64-with-glibc2.35
             related packages: typing_extensions-4.12.2
@arpit15 arpit15 added the bug Something isn't working label Sep 13, 2024
@arpit15
Copy link
Author

arpit15 commented Sep 19, 2024

I am wondering if there is any suggestion on this. Without updating the dependencies, I am afraid I can't use this library.

@Peter-van-Tol
Copy link
Owner

Peter-van-Tol commented Sep 19, 2024

Thank you for considering to us this library. I'll be able to change the validators this weekend. I hope that this will be quick enough for your project.

@Peter-van-Tol
Copy link
Owner

Fixed in version 1.0.0a3, available on PyPi now! 🚀

@Peter-van-Tol Peter-van-Tol self-assigned this Sep 22, 2024
@Peter-van-Tol Peter-van-Tol reopened this Sep 22, 2024
@Peter-van-Tol
Copy link
Owner

It is merged to main, however the upload to pypi has failed. Will resolve tomorrow morning.

@Peter-van-Tol
Copy link
Owner

Mistake while pushing the updated pyproject.toml. The version has now been successfully uploaded to PyPi:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants