Skip to content

Commit 0af7a87

Browse files
committed
Clean up
1 parent 35e8750 commit 0af7a87

File tree

8 files changed

+27
-24
lines changed

8 files changed

+27
-24
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ dmypy.json
131131
.DS_Store
132132
/out/*
133133
/my_container.h5
134-
/my_container.zarr
134+
/my_container.zarr

src/linkml_arrays/dumpers/hdf5_dumper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def _iterate_element(
1515
):
1616
"""Recursively iterate through the elements of a LinkML model and save them.
1717
18-
Writes Pydantic BaseModel objects as groups, slots that implement "linkml:elements"
18+
Write Pydantic BaseModel objects as groups, slots with the "array" element
1919
as datasets, and other slots as attributes.
2020
"""
2121
# get the type of the element

src/linkml_arrays/dumpers/yaml_array_file_dumper.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Base class for dumpling a LinkML model to a YAML file with paths to NumPy files."""
1+
"""Base class for dumping a LinkML model to a YAML file with paths to files containing individual arrays."""
22

33
import os
44
from abc import ABCMeta, abstractmethod
@@ -24,10 +24,9 @@ def _iterate_element(
2424
):
2525
"""Recursively iterate through the elements of a LinkML model and save them.
2626
27-
Returns a dictionary with the same structure as the input element, but with the slots
28-
that implement "linkml:elements" (arrays) are written to HDF5 files and the paths to these
29-
files are returned in the dictionary. Each array is written to an HDF5 dataset at path
30-
"/data" in a new HDF5 file.
27+
Return a dictionary with the same structure as the input element, but where the slots
28+
with the "array" element are written to an array file and the paths to these
29+
files are returned in the dictionary. The paths are relative to the output directory.
3130
3231
Raises:
3332
ValueError: If the class requires an identifier and it is not provided.

src/linkml_arrays/dumpers/yaml_dumper.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Class for dumpling a LinkML model to a YAML file."""
1+
"""Class for dumping a LinkML model to a YAML file."""
22

33
from typing import Union
44

@@ -14,8 +14,8 @@ def _iterate_element(
1414
):
1515
"""Recursively iterate through the elements of a LinkML model and save them.
1616
17-
Returns a dictionary with the same structure as the input element, but with the slots
18-
that implement "linkml:elements" (arrays) are written as lists or lists of lists.
17+
Returns a dictionary with the same structure as the input element, but where the slots
18+
with the "array" element are written as lists of lists in YAML.
1919
2020
Raises:
2121
ValueError: If the class requires an identifier and it is not provided.
@@ -35,10 +35,11 @@ def _iterate_element(
3535
ret_dict = dict()
3636
for k, v in vars(element).items():
3737
found_slot = schemaview.induced_slot(k, element_type)
38-
if "linkml:elements" in found_slot.implements:
38+
if found_slot.array:
3939
if id_slot is None and parent_identifier is None:
4040
raise ValueError("The class requires an identifier.")
41-
ret_dict[k] = v.tolist()
41+
assert isinstance(v, list)
42+
ret_dict[k] = v
4243
else:
4344
if isinstance(v, BaseModel):
4445
v2 = _iterate_element(v, schemaview, id_value)

src/linkml_arrays/dumpers/yaml_hdf5_dumper.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010

1111

1212
class YamlHdf5Dumper(YamlArrayFileDumper):
13-
"""Dumper class for LinkML models to YAML files with paths to NumPy files."""
13+
"""Dumper class for LinkML models to YAML files with paths to HDF5 files, one for each array.
14+
15+
Each array is written to an HDF5 dataset at path "/data" in a new HDF5 file.
16+
"""
1417

1518
FILE_SUFFIX = ".h5" # used in parent class
1619

1720
@classmethod
1821
def write_array(
1922
cls, array: Union[List, np.ndarray], output_file_path_no_suffix: Union[str, Path]
2023
):
21-
"""Write an array to a file."""
24+
"""Write an array to an HDF5 file."""
2225
# TODO do not assume that there is only one by this name
2326
# add suffix to the file name
2427
output_file_path = output_file_path_no_suffix.parent / (

src/linkml_arrays/dumpers/yaml_numpy_dumper.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Class for dumpling a LinkML model to a YAML file with paths to NumPy files."""
1+
"""Class for dumping a LinkML model to a YAML file with paths to NumPy files."""
22

33
from pathlib import Path
44
from typing import List, Union
@@ -9,15 +9,18 @@
99

1010

1111
class YamlNumpyDumper(YamlArrayFileDumper):
12-
"""Dumper class for LinkML models to YAML files with paths to NumPy files."""
12+
"""Dumper class for LinkML models to YAML files with paths to NumPy .npy files, one for each array.
13+
14+
Each array is written to an HDF5 dataset at path "/data" in a new HDF5 file.
15+
"""
1316

1417
FILE_SUFFIX = ".npy" # used in parent class
1518

1619
@classmethod
1720
def write_array(
1821
cls, array: Union[List, np.ndarray], output_file_path_no_suffix: Union[str, Path]
1922
):
20-
"""Write an array to a file."""
23+
"""Write an array to a NumPy file."""
2124
# TODO do not assume that there is only one by this name
2225
# add suffix to the file name
2326
output_file_path = output_file_path_no_suffix.parent / (

src/linkml_arrays/dumpers/zarr_directory_store_dumper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ def _iterate_element(
1515
):
1616
"""Recursively iterate through the elements of a LinkML model and save them.
1717
18-
Writes Pydantic BaseModel objects as groups, slots that implement "linkml:elements"
19-
as datasets, and other slots as attributes.
18+
Write Pydantic BaseModel objects as groups, slots with the "array" element
19+
as arrays, and other slots as attributes.
2020
"""
2121
# get the type of the element
2222
element_type = type(element).__name__
2323

2424
for k, v in vars(element).items():
2525
found_slot = schemaview.induced_slot(k, element_type)
2626
if found_slot.array:
27-
# save the numpy array to an hdf5 dataset
27+
# save the numpy array to a zarr array
2828
group.create_dataset(found_slot.name, data=v)
2929
else:
3030
if isinstance(v, BaseModel):

src/linkml_arrays/loaders/yaml_loader.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
def _iterate_element(
1515
input_dict: dict, element_type: ClassDefinition, schemaview: SchemaView
1616
) -> dict:
17-
"""Recursively iterate through the elements of a LinkML model and load them into a dict.
18-
19-
Datasets are loaded into NumPy arrays.
20-
"""
17+
"""Recursively iterate through the elements of a LinkML model and load them into a dict."""
2118
ret_dict = dict()
2219
for k, v in input_dict.items():
2320
found_slot = schemaview.induced_slot(k, element_type.name)

0 commit comments

Comments
 (0)