Skip to content

Commit

Permalink
fixed issues with RootModel
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Dec 19, 2024
1 parent 3e827a2 commit 35645e1
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 171 deletions.
4 changes: 2 additions & 2 deletions src/event_model/basemodels/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class PartialEvent(BaseModel):

data: Annotated[Dict[str, Any], Field(description="The actual measurement data")]
filled: Annotated[
Union[Dict[str, Union[bool, str]], None],
Dict[str, Union[bool, str]],
Field(
default=None,
default_factory=dict,
description="Mapping each of the keys of externally-stored data to the "
"boolean False, indicating that the data has not been loaded, or to "
"foreign keys (moved here from 'data' when the data was loaded)",
Expand Down
10 changes: 5 additions & 5 deletions src/event_model/basemodels/event_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Field,
RootModel,
)
from pydantic.config import JsonDict
from typing_extensions import Annotated, Literal

Dtype = Literal["string", "number", "array", "boolean", "integer"]
Expand Down Expand Up @@ -172,7 +173,7 @@ class Configuration(BaseModel):
]


EVENT_DESCRIPTOR_EXTRA_SCHEMA = {
EVENT_DESCRIPTOR_EXTRA_SCHEMA: JsonDict = {
"patternProperties": {"^([^./]+)$": {"$ref": "#/$defs/DataType"}},
"$defs": {
"DataType": {
Expand Down Expand Up @@ -202,18 +203,17 @@ class EventDescriptor(BaseModel):
),
]
data_keys: Annotated[
Union[Dict[str, DataKey], None],
Dict[str, DataKey],
Field(
default=None,
description="This describes the data in the Event Documents.",
title="data_keys",
),
]
hints: Annotated[Union[PerObjectHint, None], Field(default=None)]
name: Annotated[
Union[str, None],
str,
Field(
default=None,
default="",
description="A human-friendly name for this data stream, such as "
"'primary' or 'baseline'.",
),
Expand Down
16 changes: 5 additions & 11 deletions src/event_model/basemodels/event_page.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
from typing import Dict, List, Optional, Union
from typing import Dict, List, Union

from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
)
from typing_extensions import Annotated


class DataFrameForFilled(RootModel):
root: Dict[str, List[Union[bool, str]]] = Field(alias="DataframeForFilled")


class DataFrameForEventPage(RootModel):
root: Dict[str, List] = Field(alias="Dataframe")
DataFrameForFilled = Dict[str, List[Union[bool, str]]]
DataFrameForEventPage = Dict[str, List]


class PartialEventPage(BaseModel):
Expand All @@ -25,13 +19,13 @@ class PartialEventPage(BaseModel):
Field(description="The actual measurement data"),
]
filled: Annotated[
Optional[DataFrameForFilled],
DataFrameForFilled,
Field(
description="Mapping each of the keys of externally-stored data to an "
"array containing the boolean False, indicating that the data has not "
"been loaded, or to foreign keys (moved here from 'data' when the data "
"was loaded)",
default=None,
default={},
),
]
timestamps: Annotated[
Expand Down
3 changes: 2 additions & 1 deletion src/event_model/basemodels/run_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Field,
RootModel,
)
from pydantic.config import JsonDict
from typing_extensions import Annotated, Literal


Expand Down Expand Up @@ -121,7 +122,7 @@ class StaticProjection(BaseModel):
]


RUN_START_EXTRA_SCHEMA = {
RUN_START_EXTRA_SCHEMA: JsonDict = {
"$defs": {
"DataType": {
"patternProperties": {"^([^./]+)$": {"$ref": "#/$defs/DataType"}},
Expand Down
10 changes: 3 additions & 7 deletions src/event_model/basemodels/run_stop.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
from typing import Any, Dict, Optional

from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
)
from pydantic import BaseModel, ConfigDict, Field, RootModel
from pydantic.config import JsonDict
from typing_extensions import Annotated, Literal


class DataType(RootModel):
root: Any = Field(alias="DataType")


RUN_STOP_EXTRA_SCHEMA = {
RUN_STOP_EXTRA_SCHEMA: JsonDict = {
"patternProperties": {"^([^./]+)$": {"$ref": "#/$defs/DataType"}},
"additionalProperties": False,
}
Expand Down
1 change: 1 addition & 0 deletions src/event_model/basemodels/stream_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class StreamResource(BaseModel):
Field(
description="Globally unique ID to the run_start document "
"this Stream Resource is associated with.",
default="",
),
]
mimetype: Annotated[
Expand Down
7 changes: 4 additions & 3 deletions src/event_model/documents/event.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# ruff: noqa
# generated by datamodel-codegen:
# filename: event.json
# timestamp: 2024-12-18T10:56:19+00:00
# timestamp: 2024-12-19T11:24:47+00:00

from __future__ import annotations

from typing import Any, Dict, Optional, TypedDict, Union
from typing import Any, Dict, TypedDict, Union, Annotated
from pydantic import Field

from typing_extensions import NotRequired

Expand All @@ -23,7 +24,7 @@ class Event(TypedDict):
"""
UID of the EventDescriptor to which this Event belongs
"""
filled: NotRequired[Optional[Dict[str, Union[bool, str]]]]
filled: NotRequired[Dict[str, Union[bool, str]]]
"""
Mapping each of the keys of externally-stored data to the boolean False, indicating that the data has not been loaded, or to foreign keys (moved here from 'data' when the data was loaded)
"""
Expand Down
6 changes: 3 additions & 3 deletions src/event_model/documents/event_descriptor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ruff: noqa
# generated by datamodel-codegen:
# filename: event_descriptor.json
# timestamp: 2024-12-18T11:01:13+00:00
# timestamp: 2024-12-19T11:40:22+00:00

from __future__ import annotations

Expand Down Expand Up @@ -141,12 +141,12 @@ class EventDescriptor(TypedDict):
"""
Readings of configurational fields necessary for interpreting data in the Events.
"""
data_keys: NotRequired[Optional[Dict[str, DataKey]]]
data_keys: Dict[str, DataKey]
"""
This describes the data in the Event Documents.
"""
hints: NotRequired[Optional[PerObjectHint]]
name: NotRequired[Optional[str]]
name: NotRequired[str]
"""
A human-friendly name for this data stream, such as 'primary' or 'baseline'.
"""
Expand Down
15 changes: 5 additions & 10 deletions src/event_model/documents/event_page.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
# ruff: noqa
# generated by datamodel-codegen:
# filename: event_page.json
# timestamp: 2024-12-18T10:56:19+00:00
# timestamp: 2024-12-19T14:19:55+00:00

from __future__ import annotations

from typing import Dict, List, Optional, TypedDict, Union
from typing import Dict, List, TypedDict, Union

from typing_extensions import NotRequired

DataFrameForEventPage = Optional[Dict[str, List]]


DataFrameForFilled = Optional[Dict[str, List[Union[bool, str]]]]


class EventPage(TypedDict):
"""
Page of documents to record a quanta of collected data
"""

data: DataFrameForEventPage
data: Dict[str, List]
"""
The actual measurement data
"""
descriptor: str
"""
The UID of the EventDescriptor to which all of the Events in this page belong
"""
filled: NotRequired[Optional[DataFrameForFilled]]
filled: NotRequired[Dict[str, List[Union[bool, str]]]]
"""
Mapping each of the keys of externally-stored data to an array containing the boolean False, indicating that the data has not been loaded, or to foreign keys (moved here from 'data' when the data was loaded)
"""
Expand All @@ -40,7 +35,7 @@ class EventPage(TypedDict):
"""
Array of Event times. This maybe different than the timestamps on each of the data entries
"""
timestamps: DataFrameForEventPage
timestamps: Dict[str, List]
"""
The timestamps of the individual measurement data
"""
Expand Down
6 changes: 3 additions & 3 deletions src/event_model/documents/partial_event.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# ruff: noqa
# generated by datamodel-codegen:
# filename: partial_event.json
# timestamp: 2024-12-18T10:40:06+00:00
# timestamp: 2024-12-19T11:24:47+00:00

from __future__ import annotations

from typing import Any, Dict, Optional, TypedDict, Union
from typing import Any, Dict, TypedDict, Union

from typing_extensions import NotRequired

Expand All @@ -15,7 +15,7 @@ class PartialEvent(TypedDict):
"""
The actual measurement data
"""
filled: NotRequired[Optional[Dict[str, Union[bool, str]]]]
filled: NotRequired[Dict[str, Union[bool, str]]]
"""
Mapping each of the keys of externally-stored data to the boolean False, indicating that the data has not been loaded, or to foreign keys (moved here from 'data' when the data was loaded)
"""
Expand Down
15 changes: 5 additions & 10 deletions src/event_model/documents/partial_event_page.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
# ruff: noqa
# generated by datamodel-codegen:
# filename: partial_event_page.json
# timestamp: 2024-12-18T10:56:19+00:00
# timestamp: 2024-12-19T14:19:55+00:00

from __future__ import annotations

from typing import Dict, List, Optional, TypedDict, Union
from typing import Dict, List, TypedDict, Union

from typing_extensions import NotRequired

DataFrameForEventPage = Optional[Dict[str, List]]


DataFrameForFilled = Optional[Dict[str, List[Union[bool, str]]]]


class PartialEventPage(TypedDict):
data: DataFrameForEventPage
data: Dict[str, List]
"""
The actual measurement data
"""
filled: NotRequired[Optional[DataFrameForFilled]]
filled: NotRequired[Dict[str, List[Union[bool, str]]]]
"""
Mapping each of the keys of externally-stored data to an array containing the boolean False, indicating that the data has not been loaded, or to foreign keys (moved here from 'data' when the data was loaded)
"""
time: List[float]
"""
Array of Event times. This maybe different than the timestamps on each of the data entries
"""
timestamps: DataFrameForEventPage
timestamps: Dict[str, List]
"""
The timestamps of the individual measurement data
"""
6 changes: 4 additions & 2 deletions src/event_model/documents/stream_resource.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# ruff: noqa
# generated by datamodel-codegen:
# filename: stream_resource.json
# timestamp: 2024-12-18T10:56:19+00:00
# timestamp: 2024-12-19T11:38:53+00:00

from __future__ import annotations

from typing import Any, Dict, TypedDict

from typing_extensions import NotRequired


class StreamResource(TypedDict):
"""
Expand All @@ -26,7 +28,7 @@ class StreamResource(TypedDict):
"""
Additional keyword arguments to pass to the Handler to read a Stream Resource
"""
run_start: str
run_start: NotRequired[str]
"""
Globally unique ID to the run_start document this Stream Resource is associated with.
"""
Expand Down
28 changes: 10 additions & 18 deletions src/event_model/schemas/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,17 @@
"filled": {
"title": "Filled",
"description": "Mapping each of the keys of externally-stored data to the boolean False, indicating that the data has not been loaded, or to foreign keys (moved here from 'data' when the data was loaded)",
"anyOf": [
{
"additionalProperties": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "string"
}
]
"type": "object",
"additionalProperties": {
"anyOf": [
{
"type": "boolean"
},
"type": "object"
},
{
"type": "null"
}
],
"default": null
{
"type": "string"
}
]
}
},
"seq_num": {
"title": "Seq Num",
Expand Down
Loading

0 comments on commit 35645e1

Please sign in to comment.