How to use the ipysheet.sheet function in ipysheet

To help you get started, we’ve selected a few ipysheet 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 QuantStack / ipysheet / ipysheet / test_all.py View on Github external
def test_to_dataframe():
    sheet = ipysheet.sheet(rows=5, columns=4)
    ipysheet.cell(0, 0, value=True)
    ipysheet.row(1, value=[2, 34, 543, 23])
    ipysheet.column(3, value=[1.2, 1.3, 1.4, 1.5, 1.6])

    df = ipysheet.to_dataframe(sheet)
    assert np.all(df['A'].tolist() == [True,   2, None, None, None])
    assert np.all(df['B'].tolist() == [None,  34, None, None, None])
    assert np.all(df['C'].tolist() == [None, 543, None, None, None])
    assert np.all(df['D'].tolist() == [1.2,  1.3,  1.4,  1.5,  1.6])

    sheet = ipysheet.sheet(rows=4, columns=4, column_headers=['c0', 'c1', 'c2', 'c3'], row_headers=['r0', 'r1', 'r2', 'r3'])
    ipysheet.cell_range(
        [
            [2, 34, 543, 23],
            [1,  1,   1,  1],
            [2,  2, 222, 22],
github QuantStack / ipysheet / ipysheet / test_all.py View on Github external
def test_cell_add():
    sheet1 = ipysheet.sheet()
    sheet2 = ipysheet.sheet()
    ipysheet.cell(0, 0, value='1')
    assert len(sheet1.cells) == 0
    assert len(sheet2.cells) == 1
    ipysheet.sheet(sheet1)
    ipysheet.cell(0, 0, value='2')
    ipysheet.cell(0, 1, value='2')
    assert len(sheet1.cells) == 2
    assert len(sheet2.cells) == 1

    with ipysheet.hold_cells():
        ipysheet.cell(1, 0, value='3')
        ipysheet.cell(1, 1, value='4')
        assert len(sheet1.cells) == 2
        assert len(sheet2.cells) == 1
    assert len(sheet1.cells) == 4
    assert len(sheet2.cells) == 1
github QuantStack / ipysheet / ipysheet / test_all.py View on Github external
def test_cell_add():
    sheet1 = ipysheet.sheet()
    sheet2 = ipysheet.sheet()
    ipysheet.cell(0, 0, value='1')
    assert len(sheet1.cells) == 0
    assert len(sheet2.cells) == 1
    ipysheet.sheet(sheet1)
    ipysheet.cell(0, 0, value='2')
    ipysheet.cell(0, 1, value='2')
    assert len(sheet1.cells) == 2
    assert len(sheet2.cells) == 1

    with ipysheet.hold_cells():
        ipysheet.cell(1, 0, value='3')
        ipysheet.cell(1, 1, value='4')
        assert len(sheet1.cells) == 2
        assert len(sheet2.cells) == 1
    assert len(sheet1.cells) == 4
github QuantStack / ipysheet / ipysheet / test_all.py View on Github external
def test_current_sheet():
    sheet1 = ipysheet.sheet()
    assert sheet1 is ipysheet.current()
    sheet2 = ipysheet.sheet()
    assert sheet2 is ipysheet.current()
    assert sheet1 is ipysheet.sheet(sheet1)
    assert sheet1 is ipysheet.current()

    sheet3 = ipysheet.sheet('key3')
    assert sheet3 is ipysheet.current()
    sheet4 = ipysheet.sheet('key4')
    assert sheet4 is ipysheet.current()
    assert sheet3 is ipysheet.sheet('key3')
    assert sheet3 is ipysheet.current()
    assert sheet4 is ipysheet.sheet('key4')
    assert sheet4 is ipysheet.current()
github QuantStack / ipysheet / ipysheet / test_all.py View on Github external
def test_cell_range():
    ipysheet.sheet(rows=3, columns=4)
    # [row][column]
    ipysheet.cell_range([[0, 1]])  # 1 row, 2 columns
    ipysheet.cell_range([[0], [2]])  # 2 rows, 1 columns
    ipysheet.cell_range([[0, 1], [2, 3]])  # 2 rows, 2 columns
    ipysheet.cell_range([[0, 1], [2, 3], [4, 5]])  # 3 rows, 2 columns
    ipysheet.cell_range([[0, 1, 9], [2, 3, 9], [4, 5, 9]])  # 3 rows, 3 columns
    ipysheet.cell_range([[0, 1, 9]], column_end=2)  # 3 rows, 3 columns
    ipysheet.cell_range([[0, 1, 9]], column_start=1)  # 1 rows, 3 columns
    with pytest.raises(ValueError):
        ipysheet.cell_range([[0, 1], [2, 3], [4, 5], [6, 7]])  # 4 rows, 2 columns
    with pytest.raises(ValueError):
        ipysheet.cell_range([[0, 1, 2, 3, 4], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7]])  # 3 rows, 5 columns
    with pytest.raises(ValueError):
        ipysheet.cell_range([[0, 1, 2, 3, 4], [2], [3, 4, 5, 6, 7]])  # not well shaped
    with pytest.raises(ValueError):
        ipysheet.cell_range([])  # empty rows
github QuantStack / ipysheet / ipysheet / test_all.py View on Github external
def test_current_sheet():
    sheet1 = ipysheet.sheet()
    assert sheet1 is ipysheet.current()
    sheet2 = ipysheet.sheet()
    assert sheet2 is ipysheet.current()
    assert sheet1 is ipysheet.sheet(sheet1)
    assert sheet1 is ipysheet.current()

    sheet3 = ipysheet.sheet('key3')
    assert sheet3 is ipysheet.current()
    sheet4 = ipysheet.sheet('key4')
    assert sheet4 is ipysheet.current()
    assert sheet3 is ipysheet.sheet('key3')
    assert sheet3 is ipysheet.current()
    assert sheet4 is ipysheet.sheet('key4')
    assert sheet4 is ipysheet.current()
github QuantStack / ipysheet / ipysheet / test_all.py View on Github external
r.value = [1, 2, 3]
    with pytest.raises(ValueError):
        r.value = [[1, 2]]
    assert r.value == transpose(valueT)

    rT = ipysheet.cell_range(valueT, transpose=True)  # 3 rows, 2 columns
    with pytest.raises(ValueError):
        rT.value = 1
    with pytest.raises(ValueError):
        rT.value = [1, 2, 3]
    with pytest.raises(ValueError):
        rT.value = [[1, 2]]
    rT.value = transpose(value)
    assert rT.value == transpose(value)

    sheet = ipysheet.sheet(rows=3, columns=4)
    assert len(sheet.cells) == 0
    with ipysheet.hold_cells():
        ipysheet.cell_range(value)
        ipysheet.cell_range(value)
        assert len(sheet.cells) == 0
    assert len(sheet.cells) == 2
github QuantStack / ipysheet / ipysheet / test_all.py View on Github external
b.value = 20
    assert c.value == 10 + 20

    a.value = 1
    b.value = 2
    assert c.row_start == 0

    @ipysheet.calculation(inputs=[a, b], output=(c, 'type'))
    def add2(a, b):  # pylint: disable=unused-variable
        return 'abcdefg'[a + b]

    assert c.type == 'd'
    b.value = 1
    assert c.type == 'c'

    ipysheet.sheet()
    a = ipysheet.cell(0, 0, value=1)
    b = ipysheet.cell(0, 0, value=widgets.IntSlider(value=2))
    c = widgets.IntSlider(max=0)
    d = ipysheet.cell(0, 0, value=1)

    @ipysheet.calculation(inputs=[a, (b, 'value'), (c, 'max')], output=d)
    def add3(a, b, c):  # pylint: disable=unused-variable
        return a + b + c

    assert d.value == 3
    a.value = 10
    assert d.value == 10+2
    b.value.value = 20
    assert d.value == 10+20
    c.max = 30
    assert d.value == 10+20+30
github QuantStack / ipysheet / ipysheet / test_all.py View on Github external
def test_to_dataframe():
    sheet = ipysheet.sheet(rows=5, columns=4)
    ipysheet.cell(0, 0, value=True)
    ipysheet.row(1, value=[2, 34, 543, 23])
    ipysheet.column(3, value=[1.2, 1.3, 1.4, 1.5, 1.6])

    df = ipysheet.to_dataframe(sheet)
    assert np.all(df['A'].tolist() == [True,   2, None, None, None])
    assert np.all(df['B'].tolist() == [None,  34, None, None, None])
    assert np.all(df['C'].tolist() == [None, 543, None, None, None])
    assert np.all(df['D'].tolist() == [1.2,  1.3,  1.4,  1.5,  1.6])

    sheet = ipysheet.sheet(rows=4, columns=4, column_headers=['c0', 'c1', 'c2', 'c3'], row_headers=['r0', 'r1', 'r2', 'r3'])
    ipysheet.cell_range(
        [
            [2, 34, 543, 23],
            [1,  1,   1,  1],
            [2,  2, 222, 22],
            [2,  0, 111, 11],
        ],
        row_start=0, column_start=0,
        transpose=True
    )

    df = ipysheet.to_dataframe(sheet)
    assert np.all(df['c0'].tolist() == [2, 34, 543, 23])
    assert np.all(df['c1'].tolist() == [1,  1,   1,  1])
    assert np.all(df['c2'].tolist() == [2,  2, 222, 22])
    assert np.all(df['c3'].tolist() == [2,  0, 111, 11])
github timkpaine / lantern / lantern / grids / grid_ipysheet.py View on Github external
if isinstance(data, pd.DataFrame):
        if 'index' not in data.columns and drop_index:
            data = data.reset_index()
        for x in data.dtypes.iteritems():
            if 'date' in str(x[1]):
                data[x[0]] = data[x[0]].astype(str)
    elif isinstance(data, pd.Series):
        data = data.reset_index()
        for x in data.dtypes.iteritems():
            if 'date' in str(x[1]):
                data[x[0]] = data[x[0]].astype(str)
    else:
        raise NotImplementedError()

    sheet = ipysheet.sheet(rows=len(data), columns=len(data.columns), column_headers=data.columns.astype(str).tolist())
    for i, col in enumerate(data.columns):
        ipysheet.column(i, data[col].values.tolist())
    return sheet