Skip to content

Commit

Permalink
1. add style=None or style='' argument for many table-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Nov 27, 2024
1 parent 2393a1e commit ab7fdfd
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 40 deletions.
1 change: 1 addition & 0 deletions ReleaseNotes/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## New features

1. add parallelisation to `GoF1DToys`
1. add `style=None` or `style=''` argument for many `table`-methods

## Backward incompatible

Expand Down
29 changes: 18 additions & 11 deletions ostap/fitting/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,8 @@ def _rds_unique_entries_ ( dataset ,
criterium = '' ,
seed = None ,
progress = False ,
report = True ) :
report = True ,
style = '' ) :

if criterium :
assert choice in ( 'min' , 'max' , 'minimal' , 'maximal' , 'minimum' , 'maximum' ) , \
Expand Down Expand Up @@ -1043,7 +1044,7 @@ def _rds_unique_entries_ ( dataset ,
row = 'Duplicated max' , '%d' % cnt.max()
rows.append ( row )
import ostap.logger.table as T
logger.info ( '%s:\n%s' % ( title , T.table ( rows , title = title , prefix = '# ' , alignment = 'lc' ) ) )
logger.info ( '%s:\n%s' % ( title , T.table ( rows , title = title , prefix = '# ' , alignment = 'lc' , style = style ) ) )

# =============================================================================
## Make a copy of dataset only with unique entries
Expand Down Expand Up @@ -2175,8 +2176,9 @@ def _ds_table_0_ ( dataset ,
first = 0 ,
last = LAST_ENTRY ,
prefix = '' ,
title = '' ) :
"""Print data set as table
title = '' ,
style = '' ) :
""" Print data set as table
"""
varset = dataset.get()
if not valid_pointer ( varset ) :
Expand Down Expand Up @@ -2313,7 +2315,7 @@ def _ds_table_0_ ( dataset ,

title = title
import ostap.logger.table as T
t = T.table ( table_data , title = title , prefix = prefix )
t = T.table ( table_data , title = title , prefix = prefix , style = style )
w = T.table_width ( t )
return t , w

Expand All @@ -2327,7 +2329,8 @@ def _ds_table_1_ ( dataset ,
first = 0 ,
last = LAST_ENTRY ,
prefix = '' ,
title = '' ) :
title = '' ,
style = '' ) :
""" Print data set as table
"""

Expand Down Expand Up @@ -2420,7 +2423,7 @@ def _ds_table_1_ ( dataset ,

title = title
import ostap.logger.table as T
t = T.table ( table_data , title = title , prefix = prefix )
t = T.table ( table_data , title = title , prefix = prefix , style = style )
w = T.table_width ( t )
return t , w

Expand All @@ -2437,7 +2440,8 @@ def _ds_table_ ( dataset ,
first = 0 ,
last = LAST_ENTRY ,
prefix = '' ,
title = '' ) :
title = '' ,
style = '' ) :
""" Print dataset in a form of the table
>>> dataset = ...
>>> print dataset.table()
Expand All @@ -2449,7 +2453,8 @@ def _ds_table_ ( dataset ,
first = first ,
last = last ,
prefix = prefix ,
title = title ) [ 0 ]
title = title ,
style = style ) [ 0 ]

# ==============================================================================
## print dataset in a form of the table
Expand All @@ -2464,7 +2469,8 @@ def _ds_table2_ ( dataset ,
first = 0 ,
last = LAST_ENTRY ,
prefix = '' ,
title = '' ) :
title = '' ,
style = '' ) :
""" Print dataset in a form of the table
>>> dataset = ...
>>> print dataset.table()
Expand All @@ -2476,7 +2482,8 @@ def _ds_table2_ ( dataset ,
first = first ,
last = last ,
prefix = prefix ,
title = title ) [ 0 ]
title = title ,
style = style ) [ 0 ]

# =============================================================================
## print DataSet
Expand Down
3 changes: 0 additions & 3 deletions ostap/logger/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ def align_column ( table , index , align = 'left') :

logger.info ( 'The table is \n%s' % table ( table_data , 'Title' , alignment = 'rrr' ) )

"""

logger.info ( 'The table is \n%s' % table ( table_data , 'Title' , alignment = 'lll' ) )
logger.info ( 'The table is \n%s' % table ( table_data , 'Title' , alignment = 'ccc' ) )
Expand All @@ -569,8 +568,6 @@ def align_column ( table , index , align = 'left') :
logger.info ( 'Use the format="%s":\n%s' % ( fmt , result ) )

logger.info ( 'Available styles: \n%s' % ( '\n'.join ( table_styles + tabulate_styles ) ) )
"""

# =============================================================================
## The END
Expand Down
4 changes: 2 additions & 2 deletions ostap/stats/counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def se_count ( values ) :
# table = counters_table ( counters , prrefix = '# ' )
# logger.info ( 'Table is \n%s' % table )
# @endcode
def counters_table ( counters , prefix = '' , title = '' ) :
def counters_table ( counters , prefix = '' , title = '' , style = None ) :
""" Make table of counters
>>> counters = .... ## sequence or mapping for counters
>>> table = counters_table ( counters , prrefix = '# ' )
Expand Down Expand Up @@ -278,7 +278,7 @@ def counters_table ( counters , prefix = '' , title = '' ) :

import ostap.logger.table as T
if not title : title = 'Table of %d counters' % len ( counters )
table = T.table ( rows , prefix = prefix , title = title , alignment = "llcccc" )
table = T.table ( rows , prefix = prefix , title = title , alignment = "llcccc" , style = style )
#
return table

Expand Down
8 changes: 4 additions & 4 deletions ostap/stats/gof_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class Estimators(object) :
"""
# ==========================================================================
## Print the summary as Table
def table ( self , title = '' , prefix = '' , width = 5 , precision = 3 ) :
def table ( self , title = '' , prefix = '' , width = 5 , precision = 3 , style = None ) :
""" Print the summary as Table
"""
import ostap.logger.table as T
Expand All @@ -417,7 +417,7 @@ def table ( self , title = '' , prefix = '' , width = 5 , precision = 3 ) :
rows.append ( row )

title = title if title else 'Goodness of 1D-fit'
return T.table ( rows , title = title , prefix = prefix , alignment = 'lcl' )
return T.table ( rows , title = title , prefix = prefix , alignment = 'lcl' , style = style )

# ============================================================================
## @class Summary
Expand Down Expand Up @@ -492,7 +492,7 @@ def row ( self , what , result , width = 5 , precision = 3 ) :

# =========================================================================
## Make a summary table
def table ( self , title = '' , prefix = '' , width = 5 , precision = 3 ) :
def table ( self , title = '' , prefix = '' , width = 5 , precision = 3 , style = None ) :
""" Make a summary table
"""
import ostap.logger.table as T
Expand Down Expand Up @@ -528,7 +528,7 @@ def table ( self , title = '' , prefix = '' , width = 5 , precision = 3 ) :
elif not title :
title = 'Goodness of 1D-fit'

return T.table ( rows , title = title , prefix = prefix , alignment = 'lccccccccccc' )
return T.table ( rows , title = title , prefix = prefix , alignment = 'lccccccccccc' , style = style )

# =========================================================================
## Draw ECDF for toys & statistical estgimator
Expand Down
4 changes: 2 additions & 2 deletions ostap/stats/moment.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def _om_rms ( obj ) :
# m = ...
# t = m.table()
# @endcode
def _om_table ( obj , title = '' , prefix = '' , standard = False ) :
def _om_table ( obj , title = '' , prefix = '' , standard = False , style = None ) :
""" Print object as a table
>>> m = ...
>>> t = m.table()
Expand Down Expand Up @@ -602,7 +602,7 @@ def _om_table ( obj , title = '' , prefix = '' , standard = False ) :
if isinstance ( obj , Ostap.Math. Moment ) : tit = 'Moment_[%d]' % obj.order
elif isinstance ( obj , Ostap.Math.WMoment ) : tit = 'WMoment_[%d]' % obj.order

return T.table ( rows , title = tit , prefix = prefix )
return T.table ( rows , title = tit , prefix = prefix , style = style )

Ostap.Math.Moment.unbiased_2nd = _om_u2nd
Ostap.Math.Moment.unbiased_3rd = _om_u3rd
Expand Down
8 changes: 4 additions & 4 deletions ostap/stats/twosamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,11 @@ def ranks2 ( self ) :

# =========================================================================
## Print the summary as Table
def table ( self , title = '' , prefix = '' , width = 5 , precision = 3 ) :
def table ( self , title = '' , prefix = '' , width = 5 , precision = 3 , style = None ) :
""" Print the summary as Table
"""
title = title if title else 'Two Sample Test'
return Estimators.table ( self , title = title , prefix = prefix , width = width , precision = precision )
return Estimators.table ( self , title = title , prefix = prefix , width = width , precision = precision , style = style )

__repr__ = table
__str__ = table
Expand Down Expand Up @@ -702,14 +702,14 @@ def ZC ( self ) :

# =========================================================================
## Print the summary as Table
def table ( self , title = '' , prefix = '' , width = 5 , precision = 3 ) :
def table ( self , title = '' , prefix = '' , width = 5 , precision = 3 , style = None ) :
""" Print the summary as Table
"""
if not title and self.nToys :
title = 'Two Sampel Test with #%d toys' % self.nToys
elif not title :
title = 'Two Sample Test'
return Summary.table ( self , title = title , prefix = prefix , width = width , precision = precision )
return Summary.table ( self , title = title , prefix = prefix , width = width , precision = precision , style = style )

__repr__ = table
__str__ = table
Expand Down
8 changes: 4 additions & 4 deletions ostap/trees/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __str__(self):
# files = ...
# print ( files.table() )
# @endcode
def table ( self , title = '' , prefix = '' ) :
def table ( self , title = '' , prefix = '' , style = '' ) :
""" Print collection of files as table
"""
rows = [ ( '#' , '#entries' , 'size' , 'name' ) ]
Expand Down Expand Up @@ -258,7 +258,7 @@ def table ( self , title = '' , prefix = '' ) :

title = title if title else "Data(chain='%s')" % self.chain_name
import ostap.logger.table as T
return T.table ( rows , title = title , prefix = prefix , alignment = 'rrrw' )
return T.table ( rows , title = title , prefix = prefix , alignment = 'rrrw' , style = style )

# =========================================================================
## check operations
Expand Down Expand Up @@ -488,7 +488,7 @@ def frame2 ( self ) :
# files = ...
# print ( files.table() )
# @endcode
def table ( self , title = '' , prefix = '' ) :
def table ( self , title = '' , prefix = '' , style = '' ) :
""" Print collection of files as table
"""

Expand Down Expand Up @@ -549,7 +549,7 @@ def table ( self , title = '' , prefix = '' ) :

title = title if title else "Data2(chani1='%s',chani2='%s')" % ( self.chain1_name , self.chain2_name )
import ostap.logger.table as T
return T.table ( rows , title = title , prefix = prefix , alignment = 'rrrrw' )
return T.table ( rows , title = title , prefix = prefix , alignment = 'rrrrw' , style = style )


# =============================================================================
Expand Down
31 changes: 22 additions & 9 deletions ostap/trees/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,8 @@ def _rt_table_0_ ( tree ,
pattern = None ,
cuts = '' ,
prefix = '' ,
title = '' , *args ) :
title = '' ,
style = '' , *args ) :
""" Print tree as table
"""
## get list of branches/leaves
Expand Down Expand Up @@ -1024,7 +1025,7 @@ def _rt_table_0_ ( tree ,
if 1 < nfiles : title += '/%d files ' % nfiles

import ostap.logger.table as T
t = T.table ( table_data , title , prefix = prefix )
t = T.table ( table_data , title , prefix = prefix , style = style )
w = T.table_width ( t )
return t , w

Expand All @@ -1034,7 +1035,8 @@ def _rt_table_1_ ( tree ,
variables ,
cuts = '' ,
prefix = '' ,
title = '' , *args ) :
title = '' ,
style = '' , *args ) :
""" Print tree as table
"""
if isinstance ( variables , string_types ) :
Expand Down Expand Up @@ -1118,7 +1120,7 @@ def _rt_table_1_ ( tree ,
if 1 < nfiles : title += '/%d files ' % nfiles

import ostap.logger.table as T
t = T.table ( table_data , title , prefix = prefix )
t = T.table ( table_data , title , prefix = prefix , style = style )
w = T.table_width ( t )
return t , w

Expand Down Expand Up @@ -1206,7 +1208,12 @@ def _tl_type_short_ ( leaf ) :
# data = ...
# print dat.table()
# @endcode
def _rt_table_ ( dataset , variables = [] , cuts = '' , prefix = '' , title = '' , *args ) :
def _rt_table_ ( dataset ,
variables = [] ,
cuts = '' ,
prefix = '' ,
title = '' ,
style = '' , *args ) :
""" Print dataset in a form of the table
>>> dataset = ...
>>> print dataset.table()
Expand All @@ -1215,15 +1222,21 @@ def _rt_table_ ( dataset , variables = [] , cuts = '' , prefix = '' , title
variables ,
cuts = cuts ,
prefix = prefix ,
title = title , *args )[0]
title = title ,
style = style , *args )[0]

# ==============================================================================
## print root-tree in a form of the table
# @code
# data = ...
# print dat.table2 ()
# @endcode
def _rt_table2_ ( dataset , variables , cuts = '' , prefix = '' , title = '' , *args ) :
def _rt_table2_ ( dataset ,
variables ,
cuts = '' ,
prefix = '' ,
title = '' ,
style = '' , *args ) :
""" Print dataset in a form of the table
>>> dataset = ...
>>> print dataset.table()
Expand All @@ -1232,8 +1245,8 @@ def _rt_table2_ ( dataset , variables , cuts = '' , prefix = '' , title = ''
variables ,
cuts = cuts ,
prefix = prefix ,
title = title , *args )[0]

title = title ,
style = style , *args )[0]

# =============================================================================
## print DataSet
Expand Down
2 changes: 1 addition & 1 deletion ostap/utils/gsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def setHandler ( handler , force = True ) :
import atexit
@atexit.register
def print_gsl_errors () :
"""Catch GSL errors from C++ and print the summary table at exit
""" Catch GSL errors from C++ and print the summary table at exit
"""

gsl_cnt = Ostap.Utils.GslCount
Expand Down

0 comments on commit ab7fdfd

Please sign in to comment.