Skip to content

Commit

Permalink
Fix: numpy_model.model_json_schema() error, removed the use of the ha…
Browse files Browse the repository at this point in the history
…ndler

Testing: Format check in CI
Chore: Version bump, PATCH
  • Loading branch information
caniko authored and Can H. Tartanoglu committed Aug 18, 2023
1 parent 2f545b6 commit b5611a4
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 197 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,37 @@ jobs:

- name: Install dependencies
run: |
poetry install --all-extras --with dev --with ci
poetry install --all-extras --with dev,typecheck
- name: Validate type-hints with MyPy
run: |
poetry run mypy --ignore-missing-imports \
--follow-imports=skip \
--strict-optional \
-p pydantic_numpy
format:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ "3.11" ]

steps:
- uses: actions/checkout@v3

- name: Setup the Python Environment ${{ matrix.python-version }}
uses: Qwerty-133/python-setup@v1
with:
python-version: ${{ matrix.python-version }}
skip-pre-commit: true

- name: Install dependencies
run: |
poetry install --all-extras --with format
- name: Check code formatting
run: |
poetry run black . --check --diff
poetry run isort . --check --diff
poetry run ruff check .
8 changes: 4 additions & 4 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@


format:
black .
isort .
ruff check . --fix
poetry run black .
poetry run isort .
poetry run ruff check . --fix
@echo "Formatting complete 🎉"

mypy:
mypy --ignore-missing-imports \
poetry run mypy --ignore-missing-imports \
--follow-imports=skip \
--strict-optional \
-p pydantic_numpy
482 changes: 308 additions & 174 deletions poetry.lock

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions pydantic_numpy/helper/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,14 @@ def __get_pydantic_core_schema__(

@classmethod
def __get_pydantic_json_schema__(
cls, _core_schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler
cls, _core_schema: core_schema.CoreSchema, _handler: GetJsonSchemaHandler
) -> JsonSchemaValue:
return handler(
dict(
type=(
f"np.ndarray[{_int_to_dim_type[cls.dimensions] if cls.dimensions else 'Any'}, "
f"{np.dtype[cls.data_type.__name__] if _data_type_resolver(cls.data_type) else cls.data_type}]" # type: ignore[name-defined]
),
strict_data_typing=cls.strict_data_typing,
)
return dict(
type=(
f"np.ndarray[{_int_to_dim_type[cls.dimensions] if cls.dimensions else 'Any'}, "
f"np.dtype[{cls.data_type.__name__ if _data_type_resolver(cls.data_type) else 'Any'}]"
),
strict_data_typing=cls.strict_data_typing,
)


Expand Down
11 changes: 8 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pydantic_numpy"
version = "3.1.4"
version = "3.1.5"
description = "Pydantic Model integration of the NumPy array"
authors = ["Can H. Tartanoglu", "Christoph Heindl"]
maintainers = ["Can H. Tartanoglu <[email protected]>"]
Expand Down Expand Up @@ -32,9 +32,13 @@ parameterized = "^0.9.0"
hypothesis = "^6.82.0"
setuptools = "^68.0.0"

[tool.poetry.group.format.dependencies]
black = "^23.7.0"
isort = "^5.12.0"
ruff = "^0.0.285"

[tool.poetry.group.ci.dependencies]
mypy = "^1.4.1"
[tool.poetry.group.typecheck.dependencies]
mypy = "*"

[tool.black]
line-length = 120
Expand All @@ -46,6 +50,7 @@ profile = "black"
[tool.ruff]
line-length = 120
ignore-init-module-imports = true
ignore = ["F401", "F403", "F405"]

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
2 changes: 0 additions & 2 deletions tests/helper/cache.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from functools import cache
from typing import Optional

import numpy as np
import numpy.typing as npt
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from pydantic import BaseModel

Expand Down
1 change: 0 additions & 1 deletion tests/test_np_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import pytest
from hypothesis.extra.numpy import arrays

from pydantic_numpy.model import NumpyModel
from pydantic_numpy.model.np_model import model_agnostic_load
Expand Down
10 changes: 10 additions & 0 deletions tests/test_pydantic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pydantic_numpy.model import NumpyModel
from pydantic_numpy.typing import NpNDArray


class TestModel(NumpyModel):
array: NpNDArray


def test_model_json_schema():
assert TestModel.model_json_schema()
3 changes: 0 additions & 3 deletions tests/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import numpy as np
import numpy.typing as npt
import pytest
from hypothesis.extra import numpy
from hypothesis.extra.numpy import arrays
from hypothesis import strategies as st, given
from pydantic import ValidationError

from pydantic_numpy.helper.validation import PydanticNumpyMultiArrayNumpyFileOnFilePath
Expand Down

0 comments on commit b5611a4

Please sign in to comment.