22
33__all__ = ['dict2obj' , 'obj2dict' , 'repr_dict' , 'is_listy' , 'shufflish' , 'mapped' , 'IterLen' , 'ReindexCollection' ,
44 'maybe_open' , 'image_size' , 'bunzip' , 'join_path_file' , 'loads' , 'loads_multi' , 'untar_dir' , 'repo_details' ,
5- 'run' , 'open_file' , 'save_pickle' , 'load_pickle' , 'truncstr' , 'spark_chars' , 'sparkline ' , 'autostart ' ,
6- 'EventTimer' , 'stringfmt_names' , 'PartialFormatter' , 'partial_format' , 'utc2local' , 'local2utc' , 'trace ' ,
7- 'round_multiple' , 'modified_env' , 'ContextManagers' , 'str2bool' , 'sort_by_run' ]
5+ 'run' , 'open_file' , 'save_pickle' , 'load_pickle' , 'truncstr' , 'spark_chars' , 'ceil ' , 'sparkline ' ,
6+ 'autostart' , ' EventTimer' , 'stringfmt_names' , 'PartialFormatter' , 'partial_format' , 'utc2local' , 'local2utc' ,
7+ 'trace' , ' round_multiple' , 'modified_env' , 'ContextManagers' , 'str2bool' , 'sort_by_run' ]
88
99# Cell
1010from .imports import *
@@ -242,10 +242,12 @@ def truncstr(s:str, maxlen:int, suf:str='…', space='')->str:
242242spark_chars = '▁▂▃▅▆▇'
243243
244244# Cell
245- def _sparkchar (x , mn , incr , empty_zero ):
245+ def ceil (x , lim = None ): return x if (not lim or x <= lim ) else lim
246+
247+ def _sparkchar (x , mn , mx , incr , empty_zero ):
246248 if x is None or (empty_zero and not x ): return ' '
247249 if incr == 0 : return spark_chars [0 ]
248- res = int ((x - mn )/ incr - 0.5 )
250+ res = int ((ceil ( x , mx ) - mn )/ incr - 0.5 )
249251 return spark_chars [res ]
250252
251253# Cell
@@ -254,7 +256,7 @@ def sparkline(data, mn=None, mx=None, empty_zero=False):
254256 valid = [o for o in data if o is not None ]
255257 if not valid : return ' '
256258 mn ,mx ,n = ifnone (mn ,min (valid )),ifnone (mx ,max (valid )),len (spark_chars )
257- res = [_sparkchar (o , mn , (mx - mn )/ n ,empty_zero ) for o in data ]
259+ res = [_sparkchar (x = o , mn = mn , mx = mx , incr = (mx - mn )/ n , empty_zero = empty_zero ) for o in data ]
258260 return '' .join (res )
259261
260262# Cell
0 commit comments