How to use the synapseclient.table.Column function in synapseclient

To help you get started, we’ve selected a few synapseclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Sage-Bionetworks / synapsePythonClient / tests / integration / test_tables.py View on Github external
def _view_setup(cls):
        # set up a file view
        folder = syn.store(Folder(name="PartialRowTestFolder" + str(uuid.uuid4()), parent=project))
        syn.store(File("~/path/doesnt/matter", name="f1", parent=folder, synapseStore=False))
        syn.store(File("~/path/doesnt/matter/again", name="f2", parent=folder, synapseStore=False))

        cols = [Column(name='foo', columnType='INTEGER'), Column(name='bar', columnType='INTEGER')]
        return syn.store(
            EntityViewSchema(name='PartialRowTestViews' + str(uuid.uuid4()), columns=cols, addDefaultViewColumns=False,
                             parent=project, scopes=[folder]))
github Sage-Bionetworks / synapsePythonClient / tests / integration / test_tables.py View on Github external
def dontruntest_big_csvs():
    cols = [Column(name='name', columnType='STRING', maximumSize=1000),
            Column(name='foo', columnType='STRING', enumValues=['foo', 'bar', 'bat']),
            Column(name='x', columnType='DOUBLE'),
            Column(name='n', columnType='INTEGER'),
            Column(name='is_bogus', columnType='BOOLEAN')]

    schema1 = syn.store(Schema(name='Big Table', columns=cols, parent=project))

    # write rows to CSV file
    with tempfile.NamedTemporaryFile(delete=False) as temp:
        schedule_for_cleanup(temp.name)
        filename = temp.name

    with io.open(filename, mode='w', encoding="utf-8", newline='') as temp:
        writer = csv.writer(temp, quoting=csv.QUOTE_NONNUMERIC, lineterminator=str(os.linesep))
        writer.writerow([col.name for col in cols])

        for i in range(10):
            for j in range(100):
                foo = cols[1].enumValues[random.randint(0, 2)]
github Sage-Bionetworks / synapsePythonClient / tests / unit / unit_test_tables.py View on Github external
def test_Schema__max_column_check():
    table = Schema(name="someName", parent="idk")
    table.addColumns(Column(name="colNum%s" % i, columnType="STRING")
                     for i in range(synapseclient.table.MAX_NUM_TABLE_COLUMNS + 1))
    assert_raises(ValueError, syn.store, table)
github Sage-Bionetworks / synapsePythonClient / tests / unit / unit_test_tables.py View on Github external
def test_RowSetTable_len():
    schema = Schema(parentId="syn123", id='syn456', columns=[Column(name='column_name', id='123')])
    rowset = RowSet(schema=schema, rows=[Row(['first row']), Row(['second row'])])
    row_set_table = RowSetTable(schema, rowset)
    assert_equals(2, len(row_set_table))
github Sage-Bionetworks / synapsePythonClient / tests / integration / test_tables.py View on Github external
def dontruntest_big_tables():
    cols = [Column(name='name', columnType='STRING', maximumSize=1000),
            Column(name='foo', columnType='STRING', enumValues=['foo', 'bar', 'bat']),
            Column(name='x', columnType='DOUBLE'),
            Column(name='n', columnType='INTEGER'),
            Column(name='is_bogus', columnType='BOOLEAN')]

    table1 = syn.store(Schema(name='Big Table', columns=cols, parent=project))

    rows_per_append = 10

    for i in range(1000):
        rows = []
        for j in range(rows_per_append):
            foo = cols[1].enumValues[random.randint(0, 2)]
            rows.append(Row(('Robot ' + str(i*rows_per_append + j), foo, random.random()*200.0, random.randint(0, 100),
                             random.random() >= 0.5)))
        syn.store(RowSet(columns=cols, schema=table1, rows=rows))
github Sage-Bionetworks / synapsePythonClient / tests / unit / unit_test_tables.py View on Github external
def test_list_of_rows_table():
    data = [["John Coltrane",  1926, 8.65, False],
            ["Miles Davis",    1926, 9.87, False],
            ["Bill Evans",     1929, 7.65, False],
            ["Paul Chambers",  1935, 5.14, False],
            ["Jimmy Cobb",     1929, 5.78, True],
            ["Scott LaFaro",   1936, 4.21, False],
            ["Sonny Rollins",  1930, 8.99, True],
            ["Kenny Burrel",   1931, 4.37, True]]

    cols = [Column(id='1', name='Name', columnType='STRING'),
            Column(id='2', name='Born', columnType='INTEGER'),
            Column(id='3', name='Hipness', columnType='DOUBLE'),
            Column(id='4', name='Living', columnType='BOOLEAN')]

    schema1 = Schema(name='Jazz Guys', columns=cols, id="syn1000002", parent="syn1000001")

    # need columns to do cast_values w/o storing
    table = Table(schema1, data, headers=[SelectColumn.from_column(col) for col in cols])

    for table_row, expected_row in zip(table, data):
        assert_equals(table_row, expected_row)

    rowset = table.asRowSet()
    for rowset_row, expected_row in zip(rowset.rows, data):
        assert_equals(rowset_row['values'], expected_row)

    table.columns = cols
github Sage-Bionetworks / synapsePythonClient / tests / integration / test_tables.py View on Github external
def dontruntest_big_csvs():
    cols = [Column(name='name', columnType='STRING', maximumSize=1000),
            Column(name='foo', columnType='STRING', enumValues=['foo', 'bar', 'bat']),
            Column(name='x', columnType='DOUBLE'),
            Column(name='n', columnType='INTEGER'),
            Column(name='is_bogus', columnType='BOOLEAN')]

    schema1 = syn.store(Schema(name='Big Table', columns=cols, parent=project))

    # write rows to CSV file
    with tempfile.NamedTemporaryFile(delete=False) as temp:
        schedule_for_cleanup(temp.name)
        filename = temp.name

    with io.open(filename, mode='w', encoding="utf-8", newline='') as temp:
        writer = csv.writer(temp, quoting=csv.QUOTE_NONNUMERIC, lineterminator=str(os.linesep))
        writer.writerow([col.name for col in cols])
github Sage-Bionetworks / synapsePythonClient / synapseclient / client.py View on Github external
yield Column(**result)
        elif isinstance(x, (list, tuple)):
            for header in x:
                try:
                    int(header)
                    yield self.getColumn(header)
                except ValueError:
                    pass
        elif isinstance(x, Schema) or utils.is_synapse_id(x):
            uri = '/entity/{id}/column'.format(id=id_of(x))
            for result in self._GET_paginated(uri, limit=limit, offset=offset):
                yield Column(**result)
        elif isinstance(x, basestring):
            uri = '/column?prefix=' + x
            for result in self._GET_paginated(uri, limit=limit, offset=offset):
                yield Column(**result)
        else:
            ValueError("Can't get columns for a %s" % type(x))
github Sage-Bionetworks / synapsePythonClient / synapseclient / client.py View on Github external
"""
        if x is None:
            uri = '/column'
            for result in self._GET_paginated(uri, limit=limit, offset=offset):
                yield Column(**result)
        elif isinstance(x, (list, tuple)):
            for header in x:
                try:
                    int(header)
                    yield self.getColumn(header)
                except ValueError:
                    pass
        elif isinstance(x, Schema) or utils.is_synapse_id(x):
            uri = '/entity/{id}/column'.format(id=id_of(x))
            for result in self._GET_paginated(uri, limit=limit, offset=offset):
                yield Column(**result)
        elif isinstance(x, basestring):
            uri = '/column?prefix=' + x
            for result in self._GET_paginated(uri, limit=limit, offset=offset):
                yield Column(**result)
        else:
            ValueError("Can't get columns for a %s" % type(x))
github Sage-Bionetworks / synapsePythonClient / synapseclient / table.py View on Github external
if isinstance(values, pd.DataFrame):
        df = values

    if df is None:
        raise ValueError("Values of type %s is not yet supported." % type(values))

    cols = list()
    for col in df:
        columnType = DTYPE_2_TABLETYPE[df[col].dtype.char]
        if columnType == 'STRING':
            maxStrLen = df[col].str.len().max()
            if maxStrLen > 1000:
                cols.append(Column(name=col, columnType='LARGETEXT', defaultValue=''))
            else:
                size = int(round(min(1000, max(30, maxStrLen*1.5))))  # Determine the length of the longest string
                cols.append(Column(name=col, columnType=columnType, maximumSize=size, defaultValue=''))
        else:
            cols.append(Column(name=col, columnType=columnType))
    return cols