Skip to content

Commit

Permalink
update pydantic>=2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tandav committed Jun 23, 2024
1 parent 56d3f9a commit ea6e038
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ push:

.PHONY: test-no-docker
test-no-docker:
/home/tandav/.cache/.virtualenvs/pitch-detectors/bin/python -m pytest -c no_docker_pytest.ini -x -v --cov pitch_detectors
/home/tandav/.cache/virtualenvs/pitch-detectors/bin/python -m pytest -c no_docker_pytest.ini -x -v --cov pitch_detectors

.PHONY: test
test: build
Expand Down
17 changes: 8 additions & 9 deletions pitch_detectors/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import numpy as np
from pydantic import BaseModel
from pydantic import root_validator

from pydantic import ConfigDict
from pydantic import model_validator
from typing_extensions import Self

class ArbitraryBaseModel(BaseModel):
class Config:
arbitrary_types_allowed = True

model_config = ConfigDict(arbitrary_types_allowed=True)

class Wav(ArbitraryBaseModel):
fs: int
Expand All @@ -19,11 +18,11 @@ class F0(ArbitraryBaseModel):
t: np.ndarray
f0: np.ndarray

@root_validator
def check_shape(cls, values: dict[str, Any]) -> dict[str, Any]: # pylint: disable=no-self-argument
if values['t'].shape != values['f0'].shape:
@model_validator(mode='after')
def check_shape(self) -> Self:
if self.t.shape != self.f0.shape:
raise ValueError('t and f0 must have the same shape')
return values
return self


class Record(ArbitraryBaseModel):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
"penn",
"nvidia-cudnn-cu11",
"tensorrt",
"pydantic",
"pydantic>=2.0",
]

[project.optional-dependencies]
Expand Down

0 comments on commit ea6e038

Please sign in to comment.