Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
type = 'numeric'
else:
type = 'text'
if choice is not None:
type = 'dropdown'
style = style or {}
if color is not None:
style['color'] = color
if background_color is not None:
style['backgroundColor'] = background_color
if font_style is not None:
style['fontStyle'] = font_style
if font_weight is not None:
style['fontWeight'] = font_weight
c = Cell(value=value, row_start=row, column_start=column, row_end=row, column_end=column,
squeeze_row=True, squeeze_column=True, type=type, style=style, choice=choice,
read_only=read_only, numeric_format=numeric_format, date_format=date_format,
renderer=renderer, **kwargs)
if _hold_cells:
_cells += (c,)
else:
_last_sheet.cells = _last_sheet.cells+(c,)
if label_left:
if column-1 < 0:
raise IndexError("cannot put label to the left of column 0")
cell(row, column-1, value=label_left, font_weight='bold')
return c
checks = False
if checks: # we found a matching type
type = type_check
break
style = style or {}
if color is not None:
style['color'] = color
if background_color is not None:
style['backgroundColor'] = background_color
if font_style is not None:
style['fontStyle'] = font_style
if font_weight is not None:
style['fontWeight'] = font_weight
c = Cell(value=value_original, row_start=row_start, column_start=column_start, row_end=row_end, column_end=column_end,
squeeze_row=squeeze_row, squeeze_column=squeeze_column, transpose=transpose, type=type,
read_only=read_only, choice=choice, renderer=renderer, numeric_format=numeric_format, date_format=date_format,
style=style, **kwargs)
if _hold_cells:
_cells += (c,)
else:
_last_sheet.cells = _last_sheet.cells+(c,)
return c
if self.transpose: # we just work with the 'correct' shape
value = transpose(value)
row_length = self.row_end - self.row_start + 1
if row_length != len(value):
raise ValueError("length or array (%d) doesn't match number of rows (%d)" % (len(value), row_length))
column_length = self.column_end - self.column_start + 1
for row in value:
if column_length != len(row):
raise ValueError("not a regular matrix, columns lengths differ")
return original_value
# Bug in traitlets, it doesn't set it, which triggers the bug fixed here:
# https://github.com/jupyter-widgets/ipywidgets/pull/1675
# which is not released yet (7.0.2 should have it)
Cell.choice.default_value = None
@widgets.register('ipysheet.Range')
class Range(widgets.Widget):
value = Union([List(), List(Instance(list))], default_value=[0, 1]).tag(sync=True)
@widgets.register('ipysheet.Sheet')
class Sheet(widgets.DOMWidget):
""""""
_view_name = Unicode('SheetView').tag(sync=True)
_model_name = Unicode('SheetModel').tag(sync=True)
_view_module = Unicode('ipysheet').tag(sync=True)
_model_module = Unicode('ipysheet').tag(sync=True)
_view_module_version = Unicode(semver_range_frontend).tag(sync=True)
_model_module_version = Unicode(semver_range_frontend).tag(sync=True)
>>> sheet = from_dataframe(df)
>>> display(sheet)
"""
import numpy as np
# According to pandas documentation: "NumPy arrays have one dtype for the
# entire array, while pandas DataFrames have one dtype per column", so it
# makes more sense to create the sheet and fill it column-wise
columns = dataframe.columns.tolist()
rows = dataframe.index.tolist()
cells = []
idx = 0
for c in columns:
arr = np.array(dataframe[c].values)
cells.append(Cell(
value=_get_cell_value(arr),
row_start=0,
row_end=len(rows) - 1,
column_start=idx,
column_end=idx,
type=_get_cell_type(arr.dtype),
squeeze_row=False,
squeeze_column=True
))
idx += 1
return Sheet(
rows=len(rows),
columns=len(columns),
cells=cells,
row_headers=[str(header) for header in rows],
if isinstance(object, Cell) and isinstance(object.value, widgets.Widget):
object = object.value
return getattr(object, trait)
def calculate(*ignore_args):
values = map(get_value, inputs)
result = f(*values)
_assign(output, result)
for input in inputs:
if isinstance(input, widgets.Widget):
object, trait = input, 'value'
else:
object, trait = input # assume it's a tuple
if isinstance(object, Cell) and isinstance(object.value, widgets.Widget):
# when it is a cell which holds a widget, we actually want the widgets' value
object.value.observe(calculate, trait)
else:
object.observe(calculate, trait)
def handle_possible_widget_change(change, trait=trait):
if isinstance(change['old'], widgets.Widget):
change['old'].unobserve(calculate, trait)
if isinstance(change['new'], widgets.Widget):
change['new'].observe(calculate, trait)
calculate()
object.observe(handle_possible_widget_change, 'value')
if initial_calculation:
calculate()
return decorator