55"""
66__all__ = ['sheet' , 'current' , 'cell' , 'calculation' , 'row' , 'column' , 'cell_range' , 'hold_cells' , 'renderer' ]
77
8- import numbers
98import six
109from contextlib import contextmanager
1110
2322
2423_common_doc = {
2524 'args' : """
26- type (string): Type of cell, options are: text, numeric, checkbox, dropdown, numeric , date, widget.
25+ type (string): Type of cell, options are: text, int, float, checkbox, dropdown , date, widget.
2726 If type is None, the type is inferred from the type of the value being passed,
28- numeric ( float or int type) , boolean (bool type), widget (any widget object), or else text.
27+ float, int, boolean (bool type), widget (any widget object), or else text.
2928 When choice is given the type will be assumed to be dropdown.
3029 The types refer (currently) to the handsontable types: https://handsontable.com/docs/6.2.2/demo-custom-renderers.html
3130 color (string): The text color in the cell
3231 background_color (string): The background color in the cell
3332 read_only (bool): Whether the cell is editable or not
34- numeric_format (string): Numbers format
33+ numeric_format (ipywidgets.widgets.trait_types.NumberFormat): Numbers format, default is 'd' for int cells, '.2f' for
34+ float cells
3535 date_format (string): Dates format
3636 time_format (string): Time format
3737 renderer (string): Renderer name to use for the cell
@@ -95,7 +95,7 @@ def current():
9595@doc_subst (_common_doc )
9696def cell (row , column , value = 0. , type = None , color = None , background_color = None ,
9797 font_style = None , font_weight = None , style = None , label_left = None , choice = None ,
98- read_only = False , numeric_format = '0.000' , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
98+ read_only = False , numeric_format = None , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
9999 """Adds a new ``Cell`` widget to the current ``Sheet``
100100
101101 Args:
@@ -111,7 +111,8 @@ def cell(row, column, value=0., type=None, color=None, background_color=None,
111111 >>> from ipysheet import sheet, cell
112112 >>>
113113 >>> s1 = sheet()
114- >>> cell(0, 0, 36.) # The Cell type will be 'numeric'
114+ >>> cell(0, 0, 36) # The Cell type will be 'int'
115+ >>> cell(0, 0, 36.3) # The Cell type will be 'float'
115116 >>> cell(1, 0, True) # The Cell type will be 'checkbox'
116117 >>> cell(0, 1, 'Hello World!') # The Cell type will be 'text'
117118 >>> c = cell(1, 1, True)
@@ -121,8 +122,10 @@ def cell(row, column, value=0., type=None, color=None, background_color=None,
121122 if type is None :
122123 if isinstance (value , bool ):
123124 type = 'checkbox'
124- elif isinstance (value , numbers .Number ):
125- type = 'numeric'
125+ elif isinstance (value , int ):
126+ type = 'int'
127+ elif isinstance (value , float ):
128+ type = 'float'
126129 elif isinstance (value , widgets .Widget ):
127130 type = 'widget'
128131 else :
@@ -157,7 +160,7 @@ def cell(row, column, value=0., type=None, color=None, background_color=None,
157160@doc_subst (_common_doc )
158161def row (row , value , column_start = 0 , column_end = None , type = None , color = None , background_color = None ,
159162 font_style = None , font_weight = None , style = None , choice = None ,
160- read_only = False , numeric_format = '0.000' , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
163+ read_only = False , numeric_format = None , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
161164 """Create a ``Cell`` widget, representing multiple cells in a sheet, in a horizontal row
162165
163166 Args:
@@ -187,7 +190,7 @@ def row(row, value, column_start=0, column_end=None, type=None, color=None, back
187190@doc_subst (_common_doc )
188191def column (column , value , row_start = 0 , row_end = None , type = None , color = None , background_color = None ,
189192 font_style = None , font_weight = None , style = None , choice = None ,
190- read_only = False , numeric_format = '0.000' , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
193+ read_only = False , numeric_format = None , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
191194 """Create a ``Cell`` widget, representing multiple cells in a sheet, in a vertical column
192195
193196 Args:
@@ -219,7 +222,7 @@ def cell_range(value,
219222 row_start = 0 , column_start = 0 , row_end = None , column_end = None , transpose = False ,
220223 squeeze_row = False , squeeze_column = False , type = None , color = None , background_color = None ,
221224 font_style = None , font_weight = None , style = None , choice = None ,
222- read_only = False , numeric_format = '0.000' , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
225+ read_only = False , numeric_format = None , date_format = 'YYYY/MM/DD' , renderer = None , ** kwargs ):
223226 """Create a ``Cell`` widget, representing multiple cells in a sheet
224227
225228 Args:
@@ -278,7 +281,8 @@ def cell_range(value,
278281 # see if we an infer a type from the data, otherwise leave it None
279282 if type is None :
280283 type_check_map = [('checkbox' , lambda x : isinstance (x , bool )),
281- ('numeric' , lambda x : isinstance (x , numbers .Number )),
284+ ('int' , lambda x : isinstance (x , int )),
285+ ('float' , lambda x : isinstance (x , float ) or isinstance (x , int )),
282286 ('text' , lambda x : isinstance (x , six .string_types )),
283287 ('widget' , lambda x : isinstance (x , widgets .Widget )),
284288 ]
0 commit comments