Skip to content

Commit

Permalink
ast.py: fix division by zero error
Browse files Browse the repository at this point in the history
  • Loading branch information
ickc committed Mar 26, 2021
1 parent 2db447c commit f45e993
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/pantable/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,15 +1726,23 @@ def auto_width(
temp[j + 1].append(width_int_resid)

if col_widths is None or override_width:
scale = table_width / widths_int.sum()
self.spec.col_widths = widths_int
widths_int_sum = widths_int.sum()
if widths_int_sum > 0.:
scale = table_width / widths_int_sum
self.spec.col_widths = widths_int * scale
else:
self.spec.col_widths = np.zeros_like(col_widths)
else:
is_defaults = np.isnan(col_widths)
table_width_spent = np.nansum(col_widths)
# assume a normalized table
scale = (table_width - table_width_spent) / widths_int[is_defaults].sum()
# modified in-place
col_widths[is_defaults] = widths_int[is_defaults] * scale
widths_int_sum = widths_int[is_defaults].sum()
if widths_int_sum > 0.:
table_width_spent = np.nansum(col_widths)
# assume a normalized table
scale = (table_width - table_width_spent) / widths_int_sum
# modified in-place
col_widths[is_defaults] = widths_int[is_defaults] * scale
else:
col_widths[is_defaults] = 0.


class PanTableMarkdown(PanTableStr):
Expand Down

0 comments on commit f45e993

Please sign in to comment.