Skip to content

Commit a2f0613

Browse files
Merge pull request #924 from neo4j-contrib/task/fix-typing-stubs-2
Task/fix typing stubs 2
2 parents f471588 + 6ec82cb commit a2f0613

49 files changed

Lines changed: 58 additions & 2107 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/type-checking.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

neomodel/async_/match.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,18 @@ async def _execute(self, lazy: bool = False, dict_output: bool = False) -> Any:
12191219
yield result
12201220

12211221

1222+
@dataclass
1223+
class Path:
1224+
"""Path traversal definition."""
1225+
1226+
value: str
1227+
optional: bool = False
1228+
include_nodes_in_return: bool = True
1229+
include_rels_in_return: bool = True
1230+
relation_filtering: bool = False
1231+
alias: str | None = None
1232+
1233+
12221234
class AsyncBaseSet:
12231235
"""
12241236
Base class for all node sets.
@@ -1229,6 +1241,10 @@ class AsyncBaseSet:
12291241
query_cls = AsyncQueryBuilder
12301242
source_class: type[AsyncStructuredNode]
12311243

1244+
# Attributes defined in subclasses (AsyncNodeSet)
1245+
_unique_variables: list[str]
1246+
relations_to_fetch: list[Path]
1247+
12321248
async def all(self, lazy: bool = False) -> list:
12331249
"""
12341250
Return all nodes belonging to the set
@@ -1300,18 +1316,6 @@ async def get_item(self, key: int | slice) -> Optional["AsyncBaseSet"]:
13001316
return _first_item
13011317

13021318

1303-
@dataclass
1304-
class Path:
1305-
"""Path traversal definition."""
1306-
1307-
value: str
1308-
optional: bool = False
1309-
include_nodes_in_return: bool = True
1310-
include_rels_in_return: bool = True
1311-
relation_filtering: bool = False
1312-
alias: str | None = None
1313-
1314-
13151319
@dataclass
13161320
class RelationNameResolver:
13171321
"""Helper to refer to a relation variable name.

neomodel/async_/relationship_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ def deflate_relationship_properties(
617617
:return: Dictionary mapping property names to parameter placeholders (e.g. {'since': '$since'})
618618
"""
619619
rel_model = relationship.definition.get("model")
620+
assert rel_model is not None, "Relationship model is required"
620621
tmp = rel_model(**rel_props)
621622

622623
rel_prop = {}

neomodel/integration/numpy.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
"""
1717

1818

19+
from typing import Any, Literal
1920
from warnings import warn
2021

2122
try:
2223
# noinspection PyPackageRequirements
2324
from numpy import array as nparray
25+
from numpy import ndarray
2426
except ImportError:
2527
warn(
2628
"The neomodel.integration.numpy module expects numpy to be installed "
@@ -29,7 +31,11 @@
2931
raise
3032

3133

32-
def to_ndarray(query_results: tuple, dtype=None, order="K"):
34+
def to_ndarray(
35+
query_results: tuple[list[list[Any]], list[str]],
36+
dtype: Any | None = None,
37+
order: Literal["K", "A", "C", "F"] = "K",
38+
) -> ndarray:
3339
"""Convert the results of a db.cypher_query call into a numpy array.
3440
Optionally, specify a datatype and/or an order for the columns.
3541
"""

neomodel/integration/pandas.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
"""
2222

23-
23+
from typing import Any
2424
from warnings import warn
2525

2626
try:
@@ -34,7 +34,11 @@
3434
raise
3535

3636

37-
def to_dataframe(query_results: tuple, index=None, dtype=None):
37+
def to_dataframe(
38+
query_results: tuple[list[list[Any]], list[str]],
39+
index: Any | None = None,
40+
dtype: Any | None = None,
41+
) -> DataFrame:
3842
"""Convert the results of a db.cypher_query call and associated metadata
3943
into a pandas DataFrame.
4044
Optionally, specify an index and/or a datatype for the columns.
@@ -43,10 +47,18 @@ def to_dataframe(query_results: tuple, index=None, dtype=None):
4347
return DataFrame(results, columns=meta, index=index, dtype=dtype)
4448

4549

46-
def to_series(query_results: tuple, field=0, index=None, dtype=None):
50+
def to_series(
51+
query_results: tuple[list[list[Any]], list[str]],
52+
field: int = 0,
53+
index: Any | None = None,
54+
dtype: Any | None = None,
55+
) -> Series:
4756
"""Convert the results of a db.cypher_query call
4857
into a pandas Series for the given field.
4958
Optionally, specify an index and/or a datatype for the columns.
5059
"""
5160
results, _ = query_results
52-
return Series([record[field] for record in results], index=index, dtype=dtype)
61+
if dtype is None:
62+
return Series([record[field] for record in results], index=index)
63+
else:
64+
return Series([record[field] for record in results], index=index, dtype=dtype)

neomodel/sync_/match.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,18 @@ def _execute(self, lazy: bool = False, dict_output: bool = False) -> Any:
12151215
yield result
12161216

12171217

1218+
@dataclass
1219+
class Path:
1220+
"""Path traversal definition."""
1221+
1222+
value: str
1223+
optional: bool = False
1224+
include_nodes_in_return: bool = True
1225+
include_rels_in_return: bool = True
1226+
relation_filtering: bool = False
1227+
alias: str | None = None
1228+
1229+
12181230
class BaseSet:
12191231
"""
12201232
Base class for all node sets.
@@ -1225,6 +1237,10 @@ class BaseSet:
12251237
query_cls = QueryBuilder
12261238
source_class: type[StructuredNode]
12271239

1240+
# Attributes defined in subclasses (AsyncNodeSet)
1241+
_unique_variables: list[str]
1242+
relations_to_fetch: list[Path]
1243+
12281244
def all(self, lazy: bool = False) -> list:
12291245
"""
12301246
Return all nodes belonging to the set
@@ -1296,18 +1312,6 @@ def __getitem__(self, key: int | slice) -> Optional["BaseSet"]:
12961312
return _first_item
12971313

12981314

1299-
@dataclass
1300-
class Path:
1301-
"""Path traversal definition."""
1302-
1303-
value: str
1304-
optional: bool = False
1305-
include_nodes_in_return: bool = True
1306-
include_rels_in_return: bool = True
1307-
relation_filtering: bool = False
1308-
alias: str | None = None
1309-
1310-
13111315
@dataclass
13121316
class RelationNameResolver:
13131317
"""Helper to refer to a relation variable name.

neomodel/sync_/relationship_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ def deflate_relationship_properties(
597597
:return: Dictionary mapping property names to parameter placeholders (e.g. {'since': '$since'})
598598
"""
599599
rel_model = relationship.definition.get("model")
600+
assert rel_model is not None, "Relationship model is required"
600601
tmp = rel_model(**rel_props)
601602

602603
rel_prop = {}

out/neomodel/__init__.pyi

Lines changed: 0 additions & 20 deletions
This file was deleted.

out/neomodel/_version.pyi

Lines changed: 0 additions & 1 deletion
This file was deleted.

out/neomodel/async_/__init__.pyi

Whitespace-only changes.

0 commit comments

Comments
 (0)