Skip to content

Commit

Permalink
chore(docs): improve async docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Jun 6, 2024
1 parent 8dad1cf commit 9398461
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 69 deletions.
19 changes: 9 additions & 10 deletions google/cloud/bigtable/data/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ def __init__(
client. If not passed (and if no ``_http`` object is
passed), falls back to the default inferred from the
environment.
client_options (Optional[Union[dict, google.api_core.client_options.ClientOptions]]):
client_options:
Client options used to set user options
on the client. API Endpoint should be set through client_options.
Raises:
RuntimeError: if called outside of an async context (no running event loop)
ValueError: if pool_size is less than 1
RuntimeError: if called outside of an async context (no running event loop)
ValueError: if pool_size is less than 1
"""
# set up transport in registry
transport_str = f"pooled_grpc_asyncio_{pool_size}"
Expand Down Expand Up @@ -711,14 +711,13 @@ async def read_rows_sharded(
Runs a sharded query in parallel, then return the results in a single list.
Results will be returned in the order of the input queries.
This function is intended to be run on the results on a query.shard() call:
This function is intended to be run on the results on a query.shard() call.
For example::
```
table_shard_keys = await table.sample_row_keys()
query = ReadRowsQuery(...)
shard_queries = query.shard(table_shard_keys)
results = await table.read_rows_sharded(shard_queries)
```
table_shard_keys = await table.sample_row_keys()
query = ReadRowsQuery(...)
shard_queries = query.shard(table_shard_keys)
results = await table.read_rows_sharded(shard_queries)
Args:
sharded_query: a sharded query to execute
Expand Down
29 changes: 13 additions & 16 deletions google/cloud/bigtable/data/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ def _from_dict(cls, input_dict: dict[str, Any]) -> Mutation:
Create a `Mutation` instance from a dictionary representation.
Args:
input_dict (dict[str, Any]): A dictionary representation of the mutation.
input_dict: A dictionary representation of the mutation.
Returns:
Mutation: A Mutation instance created from the dictionary.
Raises:
ValueError: If the input dictionary is invalid or does not represent a valid mutation type.
"""
Expand Down Expand Up @@ -139,10 +137,10 @@ class SetCell(Mutation):
Mutation to set the value of a cell.
Args:
family (str): The name of the column family to which the new cell belongs.
qualifier (bytes | str): The column qualifier of the new cell.
new_value (bytes | str | int): The value of the new cell.
timestamp_micros (int | None): The timestamp of the new cell. If `None`,
family: The name of the column family to which the new cell belongs.
qualifier: The column qualifier of the new cell.
new_value: The value of the new cell.
timestamp_micros: The timestamp of the new cell. If `None`,
the current timestamp will be used. Timestamps will be sent with
millisecond precision. Extra precision will be truncated. If -1, the
server will assign a timestamp. Note that `SetCell` mutations with
Expand Down Expand Up @@ -207,13 +205,12 @@ class DeleteRangeFromColumn(Mutation):
Mutation to delete a range of cells from a column.
Args:
family (str): The name of the column family.
qualifier (bytes): The column qualifier.
start_timestamp_micros (int | None): The start timestamp of the range to
family: The name of the column family.
qualifier: The column qualifier.
start_timestamp_micros: The start timestamp of the range to
delete. `None` represents 0. Defaults to `None`.
end_timestamp_micros (int | None): The end timestamp of the range to
end_timestamp_micros: The end timestamp of the range to
delete. `None` represents infinity. Defaults to `None`.
Raises:
ValueError: If `start_timestamp_micros` is greater than `end_timestamp_micros`.
"""
Expand Down Expand Up @@ -254,7 +251,7 @@ class DeleteAllFromFamily(Mutation):
Mutation to delete all cells from a column family.
Args:
family_to_delete (str): The name of the column family to delete.
family_to_delete: The name of the column family to delete.
"""

family_to_delete: str
Expand Down Expand Up @@ -287,8 +284,8 @@ class RowMutationEntry:
Bigtable table.
Args:
row_key (bytes | str): The key of the row to mutate.
mutations (Mutation | list[Mutation]): The mutation or list of mutations to apply
row_key: The key of the row to mutate.
mutations: The mutation or list of mutations to apply
to the row.
Raises:
Expand Down Expand Up @@ -358,7 +355,7 @@ def _from_dict(cls, input_dict: dict[str, Any]) -> RowMutationEntry:
Create a `RowMutationEntry` instance from a dictionary representation.
Args:
input_dict (dict[str, Any]): A dictionary representation of the mutation entry.
input_dict: A dictionary representation of the mutation entry.
Returns:
RowMutationEntry: A RowMutationEntry instance created from the dictionary.
Expand Down
12 changes: 6 additions & 6 deletions google/cloud/bigtable/data/read_modify_write_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ class IncrementRule(ReadModifyWriteRule):
Rule to increment a cell's value.
Args:
family (str):
family:
The family name of the cell to increment.
qualifier (bytes | str):
qualifier:
The qualifier of the cell to increment.
increment_amount (int):
increment_amount:
The amount to increment the cell's value. Must be between -2**63 and 2**63 (64-bit signed int).
Raises:
TypeError:
Expand Down Expand Up @@ -83,11 +83,11 @@ class AppendValueRule(ReadModifyWriteRule):
Rule to append a value to a cell's value.
Args:
family (str):
family:
The family name of the cell to append to.
qualifier (bytes | str):
qualifier:
The qualifier of the cell to append to.
append_value (bytes | str):
append_value:
The value to append to the cell's value.
Raises:
TypeError: If append_value is not bytes or str.
Expand Down
42 changes: 19 additions & 23 deletions google/cloud/bigtable/data/read_rows_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
class RowRange:
"""
Represents a range of keys in a ReadRowsQuery
Args:
start_key: The start key of the range. If empty, the range is unbounded on the left.
end_key: The end key of the range. If empty, the range is unbounded on the right.
start_is_inclusive: Whether the start key is inclusive. If None, the start key is
inclusive.
end_is_inclusive: Whether the end key is inclusive. If None, the end key is not inclusive.
Raises:
ValueError: if start_key is greater than end_key, or start_is_inclusive
ValueError: if end_is_inclusive is set when the corresponding key is None
ValueError: if start_key or end_key is not a string or bytes.
"""

__slots__ = ("_pb",)
Expand All @@ -42,18 +53,6 @@ def __init__(
start_is_inclusive: bool | None = None,
end_is_inclusive: bool | None = None,
):
"""
Args:
start_key: The start key of the range. If empty, the range is unbounded on the left.
end_key: The end key of the range. If empty, the range is unbounded on the right.
start_is_inclusive: Whether the start key is inclusive. If None, the start key is
inclusive.
end_is_inclusive: Whether the end key is inclusive. If None, the end key is not inclusive.
Raises:
ValueError: if start_key is greater than end_key, or start_is_inclusive
ValueError: if end_is_inclusive is set when the corresponding key is None
ValueError: if start_key or end_key is not a string or bytes.
"""
# convert empty key inputs to None for consistency
start_key = None if not start_key else start_key
end_key = None if not end_key else end_key
Expand Down Expand Up @@ -221,6 +220,14 @@ def __repr__(self) -> str:
class ReadRowsQuery:
"""
Class to encapsulate details of a read row request
Args:
row_keys: row keys to include in the query
a query can contain multiple keys, but ranges should be preferred
row_ranges: ranges of rows to include in the query
limit: the maximum number of rows to return. None or 0 means no limit
default: None (no limit)
row_filter: a RowFilter to apply to the query
"""

slots = ("_limit", "_filter", "_row_set")
Expand All @@ -232,17 +239,6 @@ def __init__(
limit: int | None = None,
row_filter: RowFilter | None = None,
):
"""
Create a new ReadRowsQuery
Args:
row_keys: row keys to include in the query
a query can contain multiple keys, but ranges should be preferred
row_ranges: ranges of rows to include in the query
limit: the maximum number of rows to return. None or 0 means no limit
default: None (no limit)
row_filter: a RowFilter to apply to the query
"""
if row_keys is None:
row_keys = []
if row_ranges is None:
Expand Down
25 changes: 11 additions & 14 deletions google/cloud/bigtable/data/row.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ class Row:
query.
Expected to be read-only to users, and written by backend
Can be indexed:
cells = row["family", "qualifier"]
Can be indexed by family and qualifier to get cells in the row::
cells = row["family", "qualifier"]
Args:
key: Row key
cells: List of cells in the row
"""

__slots__ = ("row_key", "cells", "_index_data")
Expand All @@ -45,14 +50,8 @@ def __init__(
cells: list[Cell],
):
"""
Initializes a Row object
Row objects are not intended to be created by users.
They are returned by the Bigtable backend.
Args:
key (bytes): Row key
cells (list[Cell]): List of cells in the row
"""
self.row_key = key
self.cells: list[Cell] = cells
Expand Down Expand Up @@ -121,9 +120,9 @@ def get_cells(
If family or qualifier not passed, will include all
Can also be accessed through indexing:
cells = row["family", "qualifier"]
cells = row["family"]
Can also be accessed through indexing::
cells = row["family", "qualifier"]
cells = row["family"]
Args:
family: family to filter cells by
Expand Down Expand Up @@ -172,9 +171,7 @@ def _get_all_from_family(self, family: str) -> Generator[Cell, None, None]:

def __str__(self) -> str:
"""
Human-readable string representation
.. code-block:: python
Human-readable string representation::
{
(family='fam', qualifier=b'col'): [b'value', (+1 more),],
Expand Down

0 comments on commit 9398461

Please sign in to comment.