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

Dump yaml #17

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion nwb_linkml/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies = [
"h5py>=3.9.0",
"pydantic-settings>=2.0.3",
"tqdm>=4.66.1",
'typing-extensions>=4.12.2;python_version<"3.11"',
'typing-extensions>=4.12.2;python_version<"3.13"',
"numpydantic>=1.6.0",
"black>=24.4.2",
"pandas>=2.2.2",
Expand Down
34 changes: 32 additions & 2 deletions nwb_linkml/src/nwb_linkml/adapters/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@

import os
import sys
from abc import abstractmethod
from abc import abstractmethod, ABC
from dataclasses import dataclass, field
from logging import Logger
from typing import Any, Generator, List, Literal, Optional, Tuple, Type, TypeVar, Union, overload
from typing import (
Any,
Generator,
List,
Literal,
Optional,
Tuple,
Type,
TypeVar,
Union,
overload,
Sequence,
Mapping,
)

from linkml_runtime.dumpers import yaml_dumper
from linkml_runtime.linkml_model import (
Expand Down Expand Up @@ -273,6 +286,23 @@ def walk_types(
yield item


class Map(ABC):
"""
The generic top-level mapping class is just a classmethod for checking if the map applies and a
method for applying the check if it does
"""

@classmethod
@abstractmethod
def check(cls, *args: Sequence, **kwargs: Mapping) -> bool:
"""Check if this map applies to the given item to read"""

@classmethod
@abstractmethod
def apply(cls, *args: Sequence, **kwargs: Mapping) -> Any:
"""Actually apply the map!"""


def is_1d(cls: Dataset | Attribute) -> bool:
"""
Check if the values of a dataset are 1-dimensional.
Expand Down
3 changes: 1 addition & 2 deletions nwb_linkml/src/nwb_linkml/adapters/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

from linkml_runtime.linkml_model.meta import SlotDefinition

from nwb_linkml.adapters.adapter import Adapter, BuildResult, defaults, is_1d
from nwb_linkml.adapters.adapter import Adapter, BuildResult, defaults, is_1d, Map
from nwb_linkml.adapters.array import ArrayAdapter
from nwb_linkml.maps import Map
from nwb_linkml.maps.dtype import handle_dtype, inlined
from nwb_schema_language import Attribute

Expand Down
4 changes: 2 additions & 2 deletions nwb_linkml/src/nwb_linkml/adapters/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

from linkml_runtime.linkml_model.meta import ArrayExpression, SlotDefinition

from nwb_linkml.adapters.adapter import BuildResult, defaults, has_attrs, is_1d, is_compound
from nwb_linkml.adapters.adapter import BuildResult, defaults, has_attrs, is_1d, is_compound, Map
from nwb_linkml.adapters.array import ArrayAdapter
from nwb_linkml.adapters.classes import ClassAdapter
from nwb_linkml.maps import QUANTITY_MAP, Map
from nwb_linkml.maps import QUANTITY_MAP
from nwb_linkml.maps.dtype import flat_to_linkml, handle_dtype, inlined
from nwb_linkml.maps.naming import camel_to_snake
from nwb_schema_language import Dataset
Expand Down
4 changes: 2 additions & 2 deletions nwb_linkml/src/nwb_linkml/generators/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ def inject_dynamictable(cls: ClassResult) -> ClassResult:
cls.cls.bases = ["AlignedDynamicTableMixin", "DynamicTable"]
elif cls.cls.name == "ElementIdentifiers":
cls.cls.bases = ["ElementIdentifiersMixin", "Data"]
# make ``value`` generic on T
# Formerly make this generic, but that breaks json serialization
if "value" in cls.cls.attributes:
cls.cls.attributes["value"].range = "Optional[T]"
cls.cls.attributes["value"].range = "Optional[NDArray]"
elif cls.cls.name == "TimeSeriesReferenceVectorData":
# in core.nwb.base, so need to inject and import again
cls.cls.bases = ["TimeSeriesReferenceVectorDataMixin", "VectorData"]
Expand Down
10 changes: 5 additions & 5 deletions nwb_linkml/src/nwb_linkml/includes/hdmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
List,
Optional,
Tuple,
TypeVar,
Union,
overload,
)
from typing_extensions import TypeVar

import numpy as np
import pandas as pd
Expand All @@ -36,8 +36,8 @@
if TYPE_CHECKING: # pragma: no cover
from nwb_models.models import VectorData, VectorIndex

T = TypeVar("T", bound=NDArray)
T_INJECT = 'T = TypeVar("T", bound=NDArray)'
T = TypeVar("T", default=NDArray)
T_INJECT = 'T = TypeVar("T", default=NDArray)'

if "pytest" in sys.modules:
from nwb_models.models import ConfiguredBaseModel
Expand Down Expand Up @@ -71,7 +71,7 @@ class DynamicTableMixin(ConfiguredBaseModel):
"""

model_config = ConfigDict(extra="allow", validate_assignment=True)
__pydantic_extra__: Dict[str, Union["VectorDataMixin", "VectorIndexMixin", "NDArray", list]]
__pydantic_extra__: Dict[str, Union["VectorDataMixin", "VectorIndexMixin"]]
NON_COLUMN_FIELDS: ClassVar[tuple[str]] = (
"id",
"name",
Expand Down Expand Up @@ -899,10 +899,10 @@ class ElementIdentifiersMixin(VectorDataMixin):
ObjectImport(name="Generic"),
ObjectImport(name="Iterable"),
ObjectImport(name="Tuple"),
ObjectImport(name="TypeVar"),
ObjectImport(name="overload"),
],
),
Import(module="typing_extensions", objects=[ObjectImport(name="TypeVar")]),
Import(
module="numpydantic", objects=[ObjectImport(name="NDArray"), ObjectImport(name="Shape")]
),
Expand Down
Loading
Loading