Skip to content

Commit e10bb44

Browse files
authored
Clean up API docs (#736)
* remove year from copy-right * amend imports where missing * improve code readability * backport improved spatial type docs from 5.0 * document `srid` values of spatial types
1 parent 9e88452 commit e10bb44

File tree

5 files changed

+98
-51
lines changed

5 files changed

+98
-51
lines changed

docs/source/api.rst

Lines changed: 77 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ For example:
270270
raise gaierror("Unexpected socket address %r" % socket_address)
271271
272272
driver = GraphDatabase.driver("neo4j://example.com:9999",
273-
auth=("neo4j", "password"),
274-
resolver=custom_resolver)
273+
auth=("neo4j", "password"),
274+
resolver=custom_resolver)
275275
276276
277277
:Default: ``None``
@@ -484,9 +484,9 @@ Name of the database to query.
484484

485485

486486
.. py:attribute:: neo4j.DEFAULT_DATABASE
487-
:noindex:
487+
:noindex:
488488

489-
This will use the default database on the Neo4j instance.
489+
This will use the default database on the Neo4j instance.
490490

491491

492492
.. Note::
@@ -501,9 +501,10 @@ Name of the database to query.
501501

502502
.. code-block:: python
503503
504-
from neo4j import GraphDatabase
505-
driver = GraphDatabase.driver(uri, auth=(user, password))
506-
session = driver.session(database="system")
504+
from neo4j import GraphDatabase
505+
506+
driver = GraphDatabase.driver(uri, auth=(user, password))
507+
session = driver.session(database="system")
507508
508509
509510
:Default: ``neo4j.DEFAULT_DATABASE``
@@ -536,9 +537,10 @@ context of the impersonated user. For this, the user for which the
536537

537538
.. code-block:: python
538539
539-
from neo4j import GraphDatabase
540-
driver = GraphDatabase.driver(uri, auth=(user, password))
541-
session = driver.session(impersonated_user="alice")
540+
from neo4j import GraphDatabase
541+
542+
driver = GraphDatabase.driver(uri, auth=(user, password))
543+
session = driver.session(impersonated_user="alice")
542544
543545
544546
:Default: ``None``
@@ -676,9 +678,10 @@ Example:
676678
return record["node_id"]
677679
678680
def set_person_name(tx, node_id, name):
679-
result = tx.run("MATCH (a:Person) WHERE id(a) = $id SET a.name = $name", id=node_id, name=name)
680-
info = result.consume()
681-
# use the info for logging etc.
681+
query = "MATCH (a:Person) WHERE id(a) = $id SET a.name = $name"
682+
result = tx.run(query, id=node_id, name=name)
683+
summary = result.consume()
684+
# use the summary for logging etc.
682685
683686
.. _managed-transactions-ref:
684687

@@ -1091,9 +1094,9 @@ Point (WGS-84) :class:`neo4j.spatial.WGS84Point`
10911094
Point
10921095
=====
10931096

1094-
10951097
.. autoclass:: neo4j.spatial.Point
1096-
:members:
1098+
:show-inheritance:
1099+
:members:
10971100

10981101

10991102
CartesianPoint
@@ -1102,31 +1105,43 @@ CartesianPoint
11021105
.. autoclass:: neo4j.spatial.CartesianPoint
11031106
:show-inheritance:
11041107

1105-
.. autoproperty:: srid
1108+
.. property:: x
1109+
:type: float
1110+
1111+
Same value as ``point[0]``.
1112+
1113+
.. property:: y
1114+
:type: float
11061115

1107-
.. autoproperty:: x
1116+
Same value as ``point[1]``.
11081117

1109-
.. autoproperty:: y
1118+
.. property:: z
1119+
:type: float
11101120

1111-
.. autoproperty:: z
1121+
Same value as ``point[2]``.
11121122

1113-
.. automethod:: count
1123+
Only available if the point is in 3D space.
11141124

1115-
.. automethod:: index
11161125

1126+
Examples
1127+
--------
11171128

11181129
.. code-block:: python
11191130
1120-
point=CartesianPoint((1.23, 4.56)
1131+
from neo4j.spatial import CartesianPoint
11211132
1122-
print(point.x, point.y)
1133+
point = CartesianPoint((1.23, 4.56)
1134+
print(point.x, point.y, point.srid)
1135+
# 1.23 4.56 7203
11231136
11241137
11251138
.. code-block:: python
11261139
1127-
point=CartesianPoint((1.23, 4.56, 7.89)
1140+
from neo4j.spatial import CartesianPoint
11281141
1129-
print(point.x, point.y, point.z)
1142+
point = CartesianPoint((1.23, 4.56, 7.89)
1143+
print(point.x, point.y, point.z, point.srid)
1144+
# 1.23 4.56 7.8 9157
11301145
11311146
11321147
WGS84Point
@@ -1135,37 +1150,61 @@ WGS84Point
11351150
.. autoclass:: neo4j.spatial.WGS84Point
11361151
:show-inheritance:
11371152
1138-
.. autoproperty:: srid
1153+
.. property:: x
1154+
:type: float
1155+
1156+
Same value as ``point[0]``.
1157+
1158+
.. property:: y
1159+
:type: float
11391160
1140-
.. autoproperty:: x
1161+
Same value as ``point[1]``.
11411162
1142-
.. autoproperty:: y
1163+
.. property:: z
1164+
:type: float
11431165
1144-
.. autoproperty:: z
1166+
Same value as ``point[2]``.
11451167
1146-
.. autoproperty:: longitude
1168+
Only available if the point is in 3D space.
11471169
1148-
.. autoproperty:: latitude
1170+
.. property:: longitude
1171+
:type: float
11491172
1150-
.. autoproperty:: height
1173+
Alias for :attr:`.x`.
11511174
1152-
.. automethod:: count
1175+
.. property:: latitude
1176+
:type: float
11531177
1154-
.. automethod:: index
1178+
Alias for :attr:`.y`.
11551179
1180+
.. property:: height
1181+
:type: float
11561182
1183+
Alias for :attr:`.z`.
11571184
1185+
Only available if the point is in 3D space.
1186+
1187+
1188+
Examples
1189+
--------
11581190
11591191
.. code-block:: python
11601192
1161-
point=WGS84Point((1.23, 4.56))
1162-
print(point.longitude, point.latitude)
1193+
from neo4j.spatial import WGS84Point
1194+
1195+
point = WGS84Point((1.23, 4.56))
1196+
print(point.longitude, point.latitude, point.srid)
1197+
# 1.23 4.56 4326
11631198
11641199
11651200
.. code-block:: python
11661201
1167-
point=WGS84Point((1.23, 4.56, 7.89))
1168-
print(point.longitude, point.latitude, point.height)
1202+
from neo4j.spatial import WGS84Point
1203+
1204+
point = WGS84Point((1.23, 4.56, 7.89))
1205+
print(point.longitude, point.latitude, point.height, point.srid)
1206+
# 1.23 4.56 7.89 4979
1207+
11691208
11701209
11711210
*******************

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
# General information about the project.
5858
project = 'Neo4j Python Driver'
59-
copyright = '2002-2020 Neo4j, Inc.'
59+
copyright = 'Neo4j, Inc.'
6060
author = 'Neo4j, Inc.'
6161

6262
# The version info for the project you're documenting, acts as replacement for

neo4j/spatial/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class Point(tuple):
5050
there is no subclass defined for the required SRID.
5151
"""
5252

53+
#: The SRID (spatial reference identifier) of the spatial data.
54+
#: A number that identifies the coordinate system the spatial type is to be
55+
#: interpreted in.
56+
#:
57+
#: :type: int
5358
srid = None
5459

5560
def __new__(cls, iterable):

neo4j/work/result.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ def create_node_tx(tx, name):
262262
result = tx.run("CREATE (n:ExampleNode { name: $name }) RETURN n", name=name)
263263
record = result.single()
264264
value = record.value()
265-
info = result.consume()
266-
return value, info
265+
summary = result.consume()
266+
return value, summary
267267
268268
with driver.session() as session:
269-
node_id, info = session.write_transaction(create_node_tx, "example")
269+
node_id, summary = session.write_transaction(create_node_tx, "example")
270270
271271
Example::
272272
@@ -277,12 +277,12 @@ def get_two_tx(tx):
277277
if x > 1:
278278
break
279279
values.append(record.values())
280-
info = result.consume() # discard the remaining records if there are any
281-
# use the info for logging etc.
282-
return values, info
280+
summary = result.consume() # discard the remaining records if there are any
281+
# use the summary for logging etc.
282+
return values, summary
283283
284284
with driver.session() as session:
285-
values, info = session.read_transaction(get_two_tx)
285+
values, summary = session.read_transaction(get_two_tx)
286286
287287
:returns: The :class:`neo4j.ResultSummary` for this result
288288
"""
@@ -322,7 +322,7 @@ def peek(self):
322322
"""Obtain the next record from this result without consuming it.
323323
This leaves the record in the buffer for further processing.
324324
325-
:returns: the next :class:`.Record` or :const:`None` if none remain
325+
:returns: the next :class:`neo4j.Record` or :const:`None` if none remain
326326
"""
327327
self._buffer(1)
328328
if self._record_buffer:

neo4j/work/simple.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,9 @@ def get_two_tx(tx):
381381
if x > 1:
382382
break
383383
values.append(record.values())
384-
info = result.consume() # discard the remaining records if there are any
385-
# use the info for logging etc.
384+
# discard the remaining records if there are any
385+
summary = result.consume()
386+
# use the summary for logging etc.
386387
return values
387388
388389
with driver.session() as session:
@@ -429,7 +430,7 @@ class Query:
429430
:param metadata: metadata attached to the query.
430431
:type metadata: dict
431432
:param timeout: seconds.
432-
:type timeout: int
433+
:type timeout: float or :const:`None`
433434
"""
434435
def __init__(self, text, metadata=None, timeout=None):
435436
self.text = text
@@ -446,6 +447,8 @@ def unit_of_work(metadata=None, timeout=None):
446447
447448
For example, a timeout may be applied::
448449
450+
from neo4j import unit_of_work
451+
449452
@unit_of_work(timeout=100)
450453
def count_people_tx(tx):
451454
result = tx.run("MATCH (a:Person) RETURN count(a) AS persons")
@@ -465,7 +468,7 @@ def count_people_tx(tx):
465468
This functionality allows to limit query/transaction execution time.
466469
Specified timeout overrides the default timeout configured in the database using ``dbms.transaction.timeout`` setting.
467470
Value should not represent a duration of zero or negative duration.
468-
:type timeout: int
471+
:type timeout: float or :const:`None`
469472
"""
470473

471474
def wrapper(f):

0 commit comments

Comments
 (0)