Skip to content

Commit 11b61b1

Browse files
jp-darkclaude
andauthored
[python] Clean-up docstrings in python-spec (#275)
* Fix docstrings to match arg order of method signatures * Fixes docstring formatting to match Google style Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5f5557e commit 11b61b1

7 files changed

Lines changed: 77 additions & 67 deletions

File tree

python-spec/src/somacore/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def open(
3535
context: The Context value to use when opening the object.
3636
platform_config: Platform configuration options specific to
3737
this open operation.
38-
Returns: The SOMA object, opened for reading.
38+
39+
Returns:
40+
The SOMA object, opened for reading.
41+
3942
Lifecycle: maturing
4043
"""
4144
...
@@ -50,6 +53,7 @@ def exists(cls, uri: str, *, context: Any | None = None) -> bool:
5053
Returns:
5154
True if the object exists and is of the correct type.
5255
False if the object does not exist, or is of a different type.
56+
5357
Lifecycle: maturing
5458
"""
5559
...

python-spec/src/somacore/collection.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ def create(
5858
5959
Args:
6060
uri: The URI where the collection will be created.
61+
6162
Returns:
6263
The newly created collection, opened for writing.
64+
6365
Lifecycle: maturing
6466
"""
6567
...
@@ -99,6 +101,7 @@ def add_new_collection(
99101
platform_config: options.PlatformConfig | None = None,
100102
) -> "BaseCollection":
101103
"""Creates a new sub-collection of this collection.
104+
102105
To add an existing collection as a sub-element of this collection,
103106
use :meth:`set` or indexed access (``coll[name] = value``) instead.
104107
@@ -140,7 +143,6 @@ def add_new_collection(
140143
kind: The type of child that should be added.
141144
uri: If provided, overrides the default URI that would be used
142145
to create this object. This may be absolute or relative.
143-
If not provided,
144146
platform_config: Platform-specific configuration options used
145147
when creating the child.
146148
@@ -247,7 +249,8 @@ def set(self, key: str, value: _Elem, *, use_relative_uri: bool | None = None) -
247249
is not possible at all, the collection should raise an error.
248250
If ``False``, will always use an absolute URI.
249251
250-
Returns: ``self``, to enable method chaining.
252+
Returns:
253+
``self``, to enable method chaining.
251254
252255
Lifecycle: maturing
253256
"""

python-spec/src/somacore/coordinates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def unit(self) -> str | None:
2626
class CoordinateSpace(Protocol):
2727
"""A coordinate space for spatial data.
2828
29-
Args:
29+
Attributes:
3030
axes: The axes of the coordinate system in order.
3131
3232
Lifecycle: experimental
@@ -58,7 +58,7 @@ def axis_names(self) -> tuple[str, ...]:
5858
class CoordinateTransform(Protocol):
5959
"""A coordinate transformation from one coordinate space to another.
6060
61-
Args:
61+
Attributes:
6262
input_axes: The names of the axes for the input coordinate space.
6363
output_axes: The names of the axes for the output coordinate space.
6464

python-spec/src/somacore/data.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,22 @@ def create(
5353
5454
Args:
5555
uri: The URI where the dataframe will be created.
56-
5756
schema: Arrow schema defining the per-column schema. This schema
5857
must define all columns, including columns to be named as index
5958
columns. If the schema includes types unsupported by the SOMA
6059
implementation, an error will be raised.
61-
60+
domain: A sequence of tuples specifying the domain of each index
61+
column. Each tuple must be a pair consisting of the minimum
62+
and maximum values storable in the index column. This sequence
63+
must have the same length as ``index_column_names``. Use
64+
``None`` for string index columns when the implementation does
65+
not support string domains.
6266
index_column_names: A list of column names to use as user-defined
6367
index columns (e.g., ``['cell_type', 'tissue_type']``).
6468
All named columns must exist in the schema, and at least one
6569
index column name is required.
66-
67-
domain:
68-
A sequence of tuples specifying the domain of each index
69-
column. Each tuple must be a pair consisting of the minimum
70-
and maximum values storable in the index column. This sequence
71-
must have the same length as ``index_column_names``. Use ``None`` for string
72-
index columns when the implementation does not support string domains.
7370
platform_config: platform-specific configuration; keys are SOMA
7471
implementation names.
75-
7672
context: Other implementation-specific configuration.
7773
7874
Returns:
@@ -110,10 +106,10 @@ def read(
110106
The default of ``None`` represents no filter. Value filter
111107
syntax is implementation-defined; see the documentation
112108
for the particular SOMA implementation for details.
109+
113110
Returns:
114111
A :class:`ReadIter` of :class:`pa.Table`s.
115112
116-
117113
**Indexing:**
118114
119115
Indexing is performed on a per-column basis for each indexed column.
@@ -203,7 +199,8 @@ def write(
203199
the index columns. The schema for the values must match
204200
the schema for the ``DataFrame``.
205201
206-
Returns: ``self``, to enable method chaining.
202+
Returns:
203+
``self``, to enable method chaining.
207204
208205
Lifecycle: maturing
209206
"""
@@ -231,7 +228,8 @@ def index_column_names(self) -> tuple[str, ...]:
231228
def domain(self) -> tuple[tuple[Any, Any], ...]:
232229
"""The allowable range of values in each index column.
233230
234-
Returns: a tuple of minimum and maximum values, inclusive,
231+
Returns:
232+
A tuple of minimum and maximum values, inclusive,
235233
storable on each index column of the dataframe.
236234
237235
Lifecycle: maturing
@@ -266,7 +264,8 @@ def create(
266264
All lengths must be in the positive int64 range. The shape can
267265
be increased after creation using :meth:`resize`.
268266
269-
Returns: The newly created array, opened for writing.
267+
Returns:
268+
The newly created array, opened for writing.
270269
271270
Lifecycle: maturing
272271
"""
@@ -308,8 +307,7 @@ def schema(self) -> pa.Schema:
308307

309308
@runtime_checkable
310309
class DenseNDArray(NDArray, Protocol):
311-
"""
312-
An N-dimensional array stored densely.
310+
"""An N-dimensional array stored densely.
313311
314312
Lifecycle: maturing
315313
"""
@@ -340,7 +338,8 @@ def read(
340338
platform_config: platform-specific configuration; keys are SOMA
341339
implementation names.
342340
343-
Returns: The data over the requested range as a tensor.
341+
Returns:
342+
The data over the requested range as a tensor.
344343
345344
**Indexing:**
346345
@@ -386,7 +385,10 @@ def write(
386385
See :meth:`read` for details about indexing.
387386
values: The values to be written to the subarray. Must have
388387
the same shape as ``coords``, and matching type to the array.
389-
Returns: ``self``, to enable method chaining.
388+
389+
Returns:
390+
``self``, to enable method chaining.
391+
390392
Lifecycle: maturing
391393
"""
392394
...
@@ -420,15 +422,16 @@ def read(
420422
coords: A per-dimension sequence of coordinates defining
421423
the range to be read.
422424
batch_size: The size of batches that should be returned from a read.
423-
See :class:`options.BatchSize` for details.
425+
See :class:`options.BatchSize` for details.
424426
partitions: Specifies that this is part of a partitioned read,
425427
and which partition to include, if present.
426428
result_order: the order to return results, specified as a
427429
:class:`~options.ResultOrder` or its string value.
428430
platform_config: platform-specific configuration; keys are SOMA
429431
implementation names.
430432
431-
Returns: The data that was requested in a :class:`SparseRead`,
433+
Returns:
434+
The data that was requested in a :class:`SparseRead`,
432435
allowing access in any supported format.
433436
434437
**Indexing:**
@@ -483,7 +486,8 @@ def write(
483486
platform_config: platform-specific configuration; keys are SOMA
484487
implementation names.
485488
486-
Returns: ``self``, to enable method chaining.
489+
Returns:
490+
``self``, to enable method chaining.
487491
488492
Lifecycle: maturing
489493
"""

python-spec/src/somacore/query/query.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929

3030

3131
class AxisColumnNames(TypedDict, total=False):
32-
"""
33-
Specifies column names for experiment axis query read operations.
32+
"""Specifies column names for experiment axis query read operations.
3433
3534
Lifecycle: maturing
3635
"""
@@ -170,12 +169,14 @@ def varp(self, layer: str) -> SparseRead:
170169

171170
def obsm(self, layer: str) -> SparseRead:
172171
"""Returns an ``obsm`` layer as a sparse read.
172+
173173
Lifecycle: maturing
174174
"""
175175
...
176176

177177
def varm(self, layer: str) -> SparseRead:
178178
"""Returns a ``varm`` layer as a sparse read.
179+
179180
Lifecycle: maturing
180181
"""
181182
...
@@ -208,25 +209,19 @@ def to_anndata(
208209
varp_layers: Sequence[str] = (),
209210
drop_levels: bool = False,
210211
) -> AnnData:
211-
"""
212-
Executes the query and return result as an ``AnnData`` in-memory object.
212+
"""Executes the query and return result as an ``AnnData`` in-memory object.
213213
214214
Args:
215215
X_name: The X layer to read and return in the ``X`` slot.
216216
column_names: The columns in the ``var`` and ``obs`` dataframes
217217
to read.
218218
X_layers: Additional X layers to read and return
219219
in the ``layers`` slot.
220-
obsm_layers:
221-
Additional obsm layers to read and return in the obsm slot.
222-
obsp_layers:
223-
Additional obsp layers to read and return in the obsp slot.
224-
varm_layers:
225-
Additional varm layers to read and return in the varm slot.
226-
varp_layers:
227-
Additional varp layers to read and return in the varp slot.
228-
drop_levels:
229-
Indicate whether unused categories on axis frames should be
220+
obsm_layers: Additional obsm layers to read and return in the obsm slot.
221+
obsp_layers: Additional obsp layers to read and return in the obsp slot.
222+
varm_layers: Additional varm layers to read and return in the varm slot.
223+
varp_layers: Additional varp layers to read and return in the varp slot.
224+
drop_levels: Indicate whether unused categories on axis frames should be
230225
dropped. By default, False, the categories which are present
231226
in the SOMA Experiment and not present in the query output
232227
are not dropped.
@@ -257,8 +252,7 @@ def __exit__(self, *_: Any) -> None: ...
257252

258253
@runtime_checkable
259254
class AxisIndexer(Protocol):
260-
"""
261-
Given a query, provides index-building services for obs/var axis.
255+
"""Given a query, provides index-building services for obs/var axis.
262256
263257
Lifecycle: maturing
264258
"""

python-spec/src/somacore/scene.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ def add_new_geometry_dataframe(
128128
subcollection: The name, or sequence of names, of the subcollection the
129129
dataframe is stored in.
130130
transform: The coordinate transformation from the scene to the dataframe.
131-
uri: If provided, overrides the default URI what would be used to create
132-
this object. This may be aboslution or relative.
133-
kwargs: Additional keyword arugments as specified in
131+
uri: If provided, overrides the default URI that would be used to create
132+
this object. This may be absolute or relative.
133+
kwargs: Additional keyword arguments as specified in
134134
:meth:`spatial.GeometryDataFrame.create`.
135135
136136
Returns:
@@ -159,9 +159,9 @@ def add_new_multiscale_image(
159159
subcollection: The name, or sequence of names, of the subcollection the
160160
dataframe is stored in.
161161
transform: The coordinate transformation from the scene to the dataframe.
162-
uri: If provided, overrides the default URI what would be used to create
163-
this object. This may be aboslution or relative.
164-
kwargs: Additional keyword arugments as specified in
162+
uri: If provided, overrides the default URI that would be used to create
163+
this object. This may be absolute or relative.
164+
kwargs: Additional keyword arguments as specified in
165165
:meth:`spatial.MultiscaleImage.create`.
166166
167167
Returns:
@@ -192,17 +192,16 @@ def add_new_point_cloud_dataframe(
192192
'transcripts', subcollection=['var', 'RNA'], **kwargs
193193
)
194194
195-
196195
See :meth:`add_new_collection` for details about child URIs.
197196
198197
Args:
199198
key: The name of the point cloud dataframe.
200199
subcollection: The name, or sequence of names, of the subcollection the
201200
dataframe is stored in.
202201
transform: The coordinate transformation from the scene to the dataframe.
203-
uri: If provided, overrides the default URI what would be used to create
204-
this object. This may be aboslution or relative.
205-
kwargs: Additional keyword arugments as specified in
202+
uri: If provided, overrides the default URI that would be used to create
203+
this object. This may be absolute or relative.
204+
kwargs: Additional keyword arguments as specified in
206205
:meth:`spatial.PointCloudDataFrame.create`.
207206
208207
Returns:
@@ -234,9 +233,9 @@ def set_transform_to_geometry_dataframe(
234233
235234
Args:
236235
key: The name of the geometry dataframe.
237-
transform: The coordinate transformation from the scene to the dataframe.
238236
subcollection: The name, or sequence of names, of the subcollection the
239237
dataframe is stored in. Defaults to ``'obsl'``.
238+
transform: The coordinate transformation from the scene to the dataframe.
240239
coordinate_space: Optional coordinate space for the dataframe. This will
241240
replace the existing coordinate space of the dataframe.
242241

0 commit comments

Comments
 (0)