Skip to content

Commit

Permalink
Allow pydantic v2 using transitional v1 support (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianeboyd committed Aug 4, 2023
1 parent 9a90a6e commit eae8c78
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
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

0 comments on commit eae8c78

Please sign in to comment.