Skip to content

Commit 3a063ec

Browse files
committed
Fix type hints.
1 parent 134b60e commit 3a063ec

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/sssom/rdf_internal.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from curies import Converter
1010
from linkml_runtime.linkml_model.meta import SlotDefinition
1111
from linkml_runtime.utils.schemaview import SchemaView
12-
from pandas import DataFrame
12+
from pandas import DataFrame, Series
1313
from rdflib import BNode, Graph, Literal, Node, URIRef
1414
from rdflib.namespace import RDF, RDFS, XSD
1515
from typing_extensions import override
@@ -36,6 +36,7 @@
3636
__all__ = ["MappingSetRDFConverter"]
3737

3838
TRIPLE = tuple[Node, Node, Node]
39+
DICT_OR_SERIES = Union[Dict[str, Any], Series]
3940
MAPPINGS_IRI = URIRef(MAPPINGS, SSSOM_URI_PREFIX)
4041
EXTENSION_DEFINITION_IRI = URIRef(EXTENSION_DEFINITIONS, SSSOM_URI_PREFIX)
4142

@@ -563,7 +564,7 @@ def _multivalue_from_rdf(self, value: Any, slot_name: str, dest: Dict[str, Any])
563564
# Conversion to RDF
564565
#
565566

566-
def dict_to_rdf(self, g: Graph, obj: Dict[str, Any]) -> Node:
567+
def dict_to_rdf(self, g: Graph, obj: DICT_OR_SERIES) -> Node:
567568
"""Export a SSSOM object to a RDF graph.
568569
569570
:param g: The graph to export the object to.
@@ -611,7 +612,7 @@ def _is_empty(self, value: Any) -> bool:
611612
"""
612613
return value is None or (hasattr(value, "__len__") and len(value) == 0)
613614

614-
def _init_dict_to_rdf(self, g: Graph, obj: Dict[str, Any]) -> Node:
615+
def _init_dict_to_rdf(self, g: Graph, obj: DICT_OR_SERIES) -> Node:
615616
"""Create the root node representing a SSSOM object.
616617
617618
Subclasses should override this method to customize the way
@@ -897,7 +898,7 @@ def msdf_to_rdf(
897898
return g
898899

899900
@override
900-
def _init_dict_to_rdf(self, g: Graph, obj: Dict[str, Any]) -> Node:
901+
def _init_dict_to_rdf(self, g: Graph, obj: DICT_OR_SERIES) -> Node:
901902
if MAPPING_SET_ID in obj:
902903
return URIRef(obj[MAPPING_SET_ID])
903904
else:
@@ -926,7 +927,7 @@ def _process_slot(self, g: Graph, subject: Node, name: str, value: Any) -> bool:
926927
return done
927928

928929
def _mapping_to_rdf(
929-
self, g: Graph, subject: Node, mapping: Dict[str, Any], hydrate: bool
930+
self, g: Graph, subject: Node, mapping: DICT_OR_SERIES, hydrate: bool
930931
) -> None:
931932
mapping_node = self.mapping_converter.dict_to_rdf(g, mapping)
932933
g.add(cast(TRIPLE, [subject, MAPPINGS_IRI, mapping_node]))
@@ -979,7 +980,7 @@ def _multivalue_from_rdf(self, value: Any, slot_name: str, dest: Dict[str, Any])
979980
dest[slot_name] = dest[slot_name] + "|" + value
980981

981982
@override
982-
def _init_dict_to_rdf(self, g: Graph, obj: Dict[str, Any]) -> Node:
983+
def _init_dict_to_rdf(self, g: Graph, obj: DICT_OR_SERIES) -> Node:
983984
if RECORD_ID in obj:
984985
return URIRef(self.ccp().expand(obj[RECORD_ID]))
985986
else:

tests/test_parsers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pathlib import Path
1111
from tempfile import TemporaryDirectory
1212
from textwrap import dedent
13-
from typing import Any, Dict, Union, get_args
13+
from typing import Any, Dict, Union, cast, get_args
1414
from xml.dom import minidom
1515

1616
import numpy as np
@@ -329,13 +329,13 @@ def test_parse_standard_and_old_style_rdf(self) -> None:
329329
CONFIDENCE: 0.7,
330330
MAPPING_DATE: date(2025, 10, 27),
331331
}
332-
assert_dict_contains(self, expected_values, msdf.df.loc[0])
332+
assert_dict_contains(self, expected_values, cast(pd.Series, msdf.df.loc[0]))
333333

334334
msdf = parse_sssom_rdf(f"{test_data_dir}/pre-standard-rdf.ttl")
335335
self.assertEqual(msdf.metadata[MAPPING_SET_ID], "https://example.org/sets/standard-rdf")
336336
self.assertEqual(msdf.metadata[LICENSE], "https://creativecommons.org/licenses/by/4.0/")
337337
self.assertEqual(msdf.metadata[PUBLICATION_DATE], date(2025, 10, 28))
338-
assert_dict_contains(self, expected_values, msdf.df.loc[0])
338+
assert_dict_contains(self, expected_values, cast(pd.Series, msdf.df.loc[0]))
339339

340340
def test_parse_rdf_with_record_id(self) -> None:
341341
"""Test parsing a RDF file containing record IDs as named resources."""

0 commit comments

Comments
 (0)