Skip to content

Commit

Permalink
Allow meta['pahfit_format'] on table and columns
Browse files Browse the repository at this point in the history
  • Loading branch information
jdtsmith committed May 9, 2024
1 parent be7cca1 commit 19e9c25
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pahfit/features/features_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@


# * Special table formatting for bounded (val, min, max) values
def fmt_func(fmt):
def fmt_func(fmt: str):
"""Format bounded variables specially."""
if fmt.startswith('%'):
fmt = fmt[1:]

def _fmt(x):
ret = f"{x['val']:{fmt}}"
if np.isnan(x['min']) and np.isnan(x['max']):
Expand All @@ -24,11 +28,13 @@ class BoundedParTableFormatter(TableFormatter):
"""
def _pformat_table(self, table, *args, **kwargs):
bpcols = []
tlfmt = table.meta.get('pahfit_format')
try:
for col in table.columns.values():
if len(col.dtype) == 3: # bounded!
bpcols.append((col, col.info.format))
col.info.format = fmt_func(col.info.format or "g")
fmt = col.meta.get('pahfit_format') or tlfmt or "g"
col.info.format = fmt_func(fmt)
return super()._pformat_table(table, *args, **kwargs)
finally:
for col, fmt in bpcols:
Expand Down

0 comments on commit 19e9c25

Please sign in to comment.