rasterio / affine

Affine transformation matrices
https://affine.readthedocs.io/en/latest/index.html
BSD 3-Clause "New" or "Revised" License
159 stars 28 forks source link

Affine class not compatible with Pydantic #80

Closed yurigba closed 1 year ago

yurigba commented 2 years ago

I wanted to use Pydantic validators for making data types. However, it does not work properly in Affine 2.3.1:

from pydantic import BaseModel
from affine import identity

class Transform(BaseModel):
    transform: Affine

Transform(transform=identity)

This returns the following error:

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
<ipython-input-45-0e11ed9741f8> in <cell line: 1>()
----> 1 Transform(transform=identity)

~/anaconda3/envs/mapOsirisv2/lib/python3.10/site-packages/pydantic/main.cpython-310-x86_64-linux-gnu.so in pydantic.main.BaseModel.__init__()

ValidationError: 1 validation error for Transform
transform
  Affine.__new__() got an unexpected keyword argument 'g' (type=type_error)

This is similar to issue #79 .

sgillies commented 1 year ago

@yurigba can you try out the code in PR #92?

sgillies commented 1 year ago

I believe this has been solved.