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

fix schema for Array classes #217

Merged
merged 3 commits into from
Mar 3, 2020
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
20 changes: 15 additions & 5 deletions qcelemental/models/align.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Optional

import numpy as np
from pydantic import validator
from pydantic import Field, validator

from ..util import blockwise_contract, blockwise_expand
from .basemodels import ProtoModel
Expand All @@ -19,10 +21,18 @@ class AlignmentMill(ProtoModel):

"""

shift: Array[float] # type: ignore
rotation: Array[float] # type: ignore
atommap: Array[int] # type: ignore
mirror: bool = False
shift: Optional[Array[float]] = Field( # type: ignore
None, description="Translation array (3,) for coordinates.",
)
rotation: Optional[Array[float]] = Field( # type: ignore
None, description="Rotation array (3, 3) for coordinates.",
)
atommap: Optional[Array[int]] = Field( # type: ignore
None, description="Atom exchange map (nat,) for coordinates.",
)
mirror: bool = Field(
False, description="Do mirror invert coordinates?",
)

class Config:
force_skip_defaults = True
Expand Down
15 changes: 15 additions & 0 deletions qcelemental/models/types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Dict

import numpy as np


Expand All @@ -15,6 +17,19 @@ def validate(cls, v):

return v

@classmethod
def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None:
dt = cls._dtype
if dt is int or np.issubdtype(dt, np.integer):
items = {"type": "number", "multipleOf": 1.0}
elif dt is float or np.issubdtype(dt, np.floating):
items = {"type": "number"}
elif dt is str or np.issubdtype(dt, np.string_):
items = {"type": "string"}
elif dt is bool or np.issubdtype(dt, np.bool_):
items = {"type": "boolean"}
field_schema.update(type="array", items=items)


class ArrayMeta(type):
def __getitem__(self, dtype):
Expand Down