JakobGM / patito

A data modelling layer built on top of polars and pydantic
MIT License
270 stars 23 forks source link

Fail to import Patito #2

Closed andreale28 closed 1 year ago

andreale28 commented 1 year ago

Hi there.

Recently, I have caught a problem when import patito as pt, which returns TypeError:

In [1]: import patito as pt
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 1
----> 1 import patito as pt

File ~/Documents/GitHub/ServerlessPolars/.venv/lib/python3.10/site-packages/patito/__init__.py:4
      1 """Patito, a data-modelling library built on top of polars and pydantic."""
      2 from polars import Expr, Series, col
----> 4 from patito import exceptions, sql
      5 from patito.exceptions import ValidationError
      6 from patito.polars import DataFrame, LazyFrame

File ~/Documents/GitHub/ServerlessPolars/.venv/lib/python3.10/site-packages/patito/exceptions.py:6
      1 """Module containing all custom exceptions raised by patito."""
      3 import pydantic
----> 6 class ValidationError(pydantic.ValidationError):
      7     """Exception raised when dataframe does not match schema."""
     10 class ErrorWrapper(pydantic.error_wrappers.ErrorWrapper):

TypeError: type 'pydantic_core._pydantic_core.ValidationError' is not an acceptable base type

Before this issue, I already used Patito successfully in my project. After I take a look, it seems that recent Patito is not compatible with Pydantic v2 which is recently introduced. In the pyproject.toml, pydantic is constraint to >= 1.7.0 that makes the poetry automatically uses Pydantic=2.0.3 and I think this causes the issue.

Could you take a look? Many thanks.

andreale28 commented 1 year ago

I think we use lock Pydantic as 1.7.0 or maybe upgrade Patito to use Pydantic V2.

JakobGM commented 1 year ago

Hey, @andreale28, thanks for the bug report!

You were quite correct in this being a problem with our incompatibility with Pydantic V2. For now I have accepted @thomasaarholt PR (thanks!), pinning Pydantic to version <= 2.0. This change should be live in version 0.5.1 soon.

I will try to follow up on Pydantic v2 support as soon as I can in the future.

Again, thanks!