Skip to content

Commit

Permalink
Correct examples in docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanFauble committed Jan 7, 2025
1 parent 606fc98 commit daabee4
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions synapseclient/models/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,12 @@ class Table(TableSynchronousProtocol, AccessControllable):
table = Table(
name="my_table",
parent_id="syn1234",
).get()
).get(include_columns=True)
# You may also get the table by id:
table = Table(
id="syn4567"
).get()
).get(include_columns=True)
table.columns["my_old_column"].name = "my_new_column"
Expand All @@ -483,32 +483,35 @@ class Table(TableSynchronousProtocol, AccessControllable):
# After the data is stored in synapse you'll be able to use the new key to access the column entry
print(table.columns["my_new_column"])
Example: Replacing all columns with a list of columns
Using the `set_columns()` method you may replace all columns in a table with a
new list of columns.
Example: Create a table with a list of columns
A list of columns may be passed in when creating a new table. The order of the
columns in the list will be the order they are stored in Synapse. If the table
already exists and you create the Table instance in this way the columns will
be appended to the end of the existing columns.
from synapseclient import Synapse
from synapseclient.models import Column, ColumnType, Table
syn = Synapse()
syn.login()
table = Table(
id="syn1234"
).get()
columns = [
Column(name="my_string_column", column_type=ColumnType.STRING),
Column(name="my_integer_column", column_type=ColumnType.INTEGER),
Column(name="my_double_column", column_type=ColumnType.DOUBLE),
Column(name="my_boolean_column", column_type=ColumnType.BOOLEAN),
]
table.set_columns(columns=columns)
table = Table(
name="my_table",
parent_id="syn1234",
columns=columns
)
table.store()
Example: Replacing all columns with a dictionary of columns
Example: Creating a table with a dictionary of columns
When specifying a number of columns via a dict setting the `name` attribute
on the `Column` object is optional. When it is not specified it will be
pulled from the key of the dict.
Expand All @@ -534,7 +537,7 @@ class Table(TableSynchronousProtocol, AccessControllable):
table.store()
Example: Replacing all columns with an OrderedDict of columns
Example: Creating a table with an OrderedDict of columns
When specifying a number of columns via a dict setting the `name` attribute
on the `Column` object is optional. When it is not specified it will be
pulled from the key of the dict.
Expand All @@ -559,7 +562,6 @@ class Table(TableSynchronousProtocol, AccessControllable):
)
table.store()
"""

id: Optional[str] = None
Expand Down

0 comments on commit daabee4

Please sign in to comment.