thinkingmachines / geowrangler

🌏 A python package for wrangling geospatial datasets
https://geowrangler.thinkingmachin.es/
MIT License
47 stars 14 forks source link

PydanticUserError encountered when importing Geowrangler libraries #213

Closed gabosantos closed 1 year ago

gabosantos commented 1 year ago
Screenshot 2023-08-14 at 1 06 42 AM

Hi,

I am simply importing Geowrangler Grids library but I am encountering a PydanticUserError. Complete error is shown below:

`PydanticUserError Traceback (most recent call last) Cell In[1], line 7 4 import numpy as np 5 from shapely.geometry import Point ----> 7 from geowrangler import grids 8 from geowrangler.datasets import geofabrik 9 import geowrangler.vector_zonal_stats as vzs

File ~/anaconda3/lib/python3.10/site-packages/geowrangler/grids.py:15 12 from typing import List, Tuple, Union 14 import h3 ---> 15 import morecantile 16 import numpy as np 17 from fastcore.basics import patch

File ~/anaconda3/lib/python3.10/site-packages/morecantile/init.py:14 11 version = "3.4.0" 13 from .commons import BoundingBox, Coords, Tile # noqa ---> 14 from .defaults import TileMatrixSets, tms # noqa 15 from .models import TileMatrixSet

File ~/anaconda3/lib/python3.10/site-packages/morecantile/defaults.py:11 8 import attr 10 from morecantile.errors import InvalidIdentifier ---> 11 from morecantile.models import TileMatrixSet 13 morecantile_tms_dir = pathlib.Path(file).parent.joinpath("data") 14 tms_paths = list(pathlib.Path(morecantile_tms_dir).glob("*.json"))

File ~/anaconda3/lib/python3.10/site-packages/morecantile/models.py:94 90 """Check if CRS has inverted AXIS (lat,lon) instead of (lon,lat).""" 91 return crs.axis_info[0].abbrev.upper() in ["Y", "LAT", "N"] ---> 94 class TMSBoundingBox(BaseModel): 95 """Bounding box""" 97 type: str = Field("BoundingBoxType", const=True)

File ~/anaconda3/lib/python3.10/site-packages/morecantile/models.py:97, in TMSBoundingBox() 94 class TMSBoundingBox(BaseModel): 95 """Bounding box""" ---> 97 type: str = Field("BoundingBoxType", const=True) 98 crs: CRSType 99 lowerCorner: BoundsType

File ~/anaconda3/lib/python3.10/site-packages/pydantic/fields.py:749, in Field(default, default_factory, alias, alias_priority, validation_alias, serialization_alias, title, description, examples, exclude, include, discriminator, json_schema_extra, frozen, validate_default, repr, init_var, kw_only, pattern, strict, gt, ge, lt, le, multiple_of, allow_inf_nan, max_digits, decimal_places, min_length, max_length, **extra) 747 const = extra.pop('const', None) # type: ignore 748 if const is not None: --> 749 raise PydanticUserError('const is removed, use Literal instead', code='removed-kwargs') 751 min_items = extra.pop('min_items', None) # type: ignore 752 if min_items is not None:

PydanticUserError: const is removed, use Literal instead

For further information visit https://errors.pydantic.dev/2.1.1/u/removed-kwargs`

Any clue on how to resolve this? Something needs to be updated within the Geowrangler modules.

butchtm commented 1 year ago

hi @gabosantos thanks for your report.

In order for us to resolve your error, would you mind sharing your environment.yml file? (just run conda env export > environment.yml )

My quick review is that you might need to downgrade your version of pydantic from 2.1.1 to 1.10.7 (as this is what geowrangler expects) but until I can replicate the error, I can't confirm this.

butchtm commented 1 year ago

upgraded morecantile to 5.0.0 and should now be compatible with pydantic 2.x.x