diff --git a/docs/versions.rst b/docs/versions.rst index 8b46b22..1c96eab 100644 --- a/docs/versions.rst +++ b/docs/versions.rst @@ -11,6 +11,10 @@ Versions and Change Log .. TODO * self.padl and r / 12 in make html width adj s/b elsewhere +5.4.1 and 5.4.1 +------------------ +* Minor bug fixes; tikz method no works for empty dataframe. + 5.4 ---- * Can now pass a namedtuple as df; it is converted to a dataframe. diff --git a/greater_tables/__init__.py b/greater_tables/__init__.py index 0a393d0..8ab7541 100644 --- a/greater_tables/__init__.py +++ b/greater_tables/__init__.py @@ -1,6 +1,6 @@ __project__ = 'greater_tables' __author__ = 'Stephen J Mildenhall' -__version__ = '5.4.1' +__version__ = '5.4.2' from . core import GT from . fabrications import * diff --git a/greater_tables/core.py b/greater_tables/core.py index 5abd967..8200f9c 100644 --- a/greater_tables/core.py +++ b/greater_tables/core.py @@ -281,7 +281,8 @@ class GT(object): if len(df) > self.config.large_warning and not self.config.large_ok: raise ValueError( - 'Large dataframe (>50 rows) and config.large_ok not set to true...do you know what you are doing?') + f'Large dataframe (>{self.config.large_warning} rows) and config.large_ok not set to true. ' + 'Set large_ok=True or increase value of large_warning.') if not df.columns.is_unique: raise ValueError('df column names are not unique') @@ -1707,7 +1708,7 @@ class GT(object): matrix_name = self.df_id # column and tikz display widths - colw = self.tex_knowledge_df['tikz_colw'].map(lambda x: np.round(x, 3)) + colw = self.tex_knowledge_df['tikz_colw'].fillna(0).round(3) tabs = self.tex_knowledge_df['recommended'].map(lambda x: np.round(x, 3)) # these are indexed with pre-TeX mangling names # colw.index = df.columns diff --git a/greater_tables/utilities.py b/greater_tables/utilities.py index 72ff600..deaf623 100644 --- a/greater_tables/utilities.py +++ b/greater_tables/utilities.py @@ -774,6 +774,7 @@ class TextOutput: Formats a single cell, wrapping text and applying padding and alignment. Returns a list of strings, each representing a line of the cell. """ + width = int(width) lines = wrap(str(text), width=width) or [""] padded_width = width + 2 * fmt.padding return [ @@ -798,7 +799,14 @@ class TextOutput: parts.append(line_fmt.index_sep) elif i > 0: parts.append(line_fmt.sep) - parts.append(line_fmt.hline * total) + try: + parts.append(line_fmt.hline * int(total)) + except: + # print('ERROR') + # print(w, fmt.padding) + # print(total, type(total)) + # print(line_fmt.hline) + raise return f"{line_fmt.begin}{''.join(parts)}{line_fmt.end}" def _make_data_row(row_fmt: DataRow, line_cells: list[str]) -> str: @@ -821,7 +829,7 @@ class TextOutput: """ max_height = max(len(c) for c in wrapped_cells) padded_cells = [ - [" " * (w + 2 * fmt.padding)] * (max_height - len(cell)) + cell + [" " * int(w + 2 * fmt.padding)] * (max_height - len(cell)) + cell for cell, w in zip(wrapped_cells, level_widths) ] return [ @@ -860,7 +868,7 @@ class TextOutput: ] max_height = max(len(c) for c in data_cells) padded = [ - c + [" " * (w + 2 * fmt.padding)] * (max_height - len(c)) + c + [" " * int(w + 2 * fmt.padding)] * (max_height - len(c)) for c, w in zip(data_cells, data_col_widths) ] for i in range(max_height):