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

Allow pydantic v2 using transitional v1 support #891

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ catalogue>=2.0.4,<2.1.0
confection>=0.0.1,<1.0.0
ml_datasets>=0.2.0,<0.3.0; python_version < "3.11"
# Third-party dependencies
pydantic>=1.7.4,!=1.8,!=1.8.1,<1.11.0
pydantic>=1.7.4,!=1.8,!=1.8.1,<3.0.0
numpy>=1.15.0; python_version < "3.9"
numpy>=1.19.0; python_version >= "3.9"
packaging>=20.0
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ install_requires =
setuptools
numpy>=1.15.0; python_version < "3.9"
numpy>=1.19.0; python_version >= "3.9"
pydantic>=1.7.4,!=1.8,!=1.8.1,<1.11.0
pydantic>=1.7.4,!=1.8,!=1.8.1,<3.0.0
packaging>=20.0
# Backports of modern Python features
dataclasses>=0.6,<1.0; python_version < "3.7"
Expand Down
6 changes: 5 additions & 1 deletion thinc/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import catalogue
import numpy
import pytest
from pydantic import BaseModel, PositiveInt, StrictBool, StrictFloat, constr

try:
from pydantic.v1 import BaseModel, PositiveInt, StrictBool, StrictFloat, constr
except ImportError:
from pydantic import BaseModel, PositiveInt, StrictBool, StrictFloat, constr # type: ignore

import thinc.config
from thinc.api import Config, Model, NumpyOps, RAdam
Expand Down
7 changes: 6 additions & 1 deletion thinc/tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import numpy
import pytest
from pydantic import ValidationError, create_model

try:
from pydantic.v1 import ValidationError, create_model
except ImportError:
from pydantic import ValidationError, create_model # type: ignore


from thinc.types import (
Floats1d,
Expand Down
8 changes: 6 additions & 2 deletions thinc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@

import numpy
from packaging.version import Version
from pydantic import ValidationError, create_model

try:
from pydantic.v1 import ValidationError, create_model
except ImportError:
from pydantic import ValidationError, create_model # type: ignore

from wasabi import table

from .compat import (
Expand Down Expand Up @@ -251,7 +256,6 @@ def to_categorical(
*,
label_smoothing: float = 0.0,
) -> FloatsXd:

if n_classes is None:
n_classes = int(numpy.max(Y) + 1) # type: ignore

Expand Down