Skip to content

Commit ee52541

Browse files
committed
Cleanup
1 parent ed7cfcf commit ee52541

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

src/curies/metamodel.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from curies import NamableReference
1111

1212
__all__ = [
13-
"from_records",
1413
"from_tsv",
14+
"iter_records",
1515
]
1616

1717
Model = TypeVar("Model", bound=BaseModel)
@@ -28,7 +28,6 @@ def from_tsv(
2828
A mapping from column names corresponding to reference fields to column names representing the labels
2929
:yields: Validated models
3030
31-
3231
Let's use a similar table, now with the prefix and identifier combine into CURIEs.
3332
3433
=========== ======== ======
@@ -39,22 +38,14 @@ def from_tsv(
3938
CHEBI:44884 pentanol CCCCCO
4039
=========== ======== ======
4140
42-
Note that there's a typo in the prefix on the fourth row in the prefix because it uses
43-
``CHOBI`` instead of ``CHEBI``. In the following code, we simulate reading that file and
44-
show where the error shows up:
41+
In the following code, we simulate reading that file and show where the error shows up:
4542
4643
.. code-block:: python
4744
48-
import csv
49-
from pydantic import BaseModel, ValidationError
50-
from curies import Converter, NamedReference
51-
from curies.metamodel import from_records
45+
from pydantic import BaseModel
5246
53-
converter = Converter.from_prefix_map(
54-
{
55-
"CHEBI": "http://purl.obolibrary.org/obo/CHEBI_",
56-
}
57-
)
47+
from curies import NamedReference
48+
from curies.metamodel import iter_records
5849
5950
6051
class Row(BaseModel):
@@ -68,16 +59,17 @@ class Row(BaseModel):
6859
{"curie": "CHEBI:44884", "name": "pentanol", "smiles": "CCCCCO"},
6960
]
7061
71-
models = list(from_records(records, Row, names={"curie": "name"}))
62+
models = list(iter_records(records, Row, names={"curie": "name"}))
7263
print(models)
7364
7465
"""
75-
with open(path) as file:
66+
path = Path(path).expanduser().resolve()
67+
with path.open() as file:
7668
reader = csv.DictReader(file, delimiter="\t")
77-
yield from from_records(reader, cls, names=names)
69+
yield from iter_records(reader, cls, names=names)
7870

7971

80-
def from_records(
72+
def iter_records(
8173
records: Iterable[dict[str, Any]], cls: type[Model], names: dict[str, str] | None = None
8274
) -> Iterable[Model]:
8375
"""Get records."""

tests/test_metamodel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pydantic import BaseModel
66

77
from curies import NamableReference
8-
from curies.metamodel import from_records
8+
from curies.metamodel import iter_records
99

1010

1111
class TestModel(unittest.TestCase):
@@ -25,7 +25,7 @@ class MM(BaseModel):
2525
{"curie": "GO:0000002", "curie_label": "Test 2"},
2626
]
2727

28-
models = list(from_records(records, MM, names=names))
28+
models = list(iter_records(records, MM, names=names))
2929
self.assertEqual(
3030
[
3131
MM(curie=NamableReference(prefix="GO", identifier="0000001", name="Test 1")),

0 commit comments

Comments
 (0)