diff --git a/greater_tables/gtcore.py b/greater_tables/gtcore.py index bf32814..0c09155 100644 --- a/greater_tables/gtcore.py +++ b/greater_tables/gtcore.py @@ -322,7 +322,7 @@ class GT(object): # self.df.columns.names = [None] * self.df.columns.nlevels self.df_id = df_short_hash(self.df) # TODO: update / change - self.str_table_fmt = str_table_fmt + # self.str_table_fmt = str_table_fmt # TODO: implement table_width_mode = table_width_mode.lower() if table_width_mode not in ('explicit', 'natural', 'breakable', 'minimum'): diff --git a/greater_tables/gtcore2.py b/greater_tables/gtcore2.py index c2dba18..d9c108b 100644 --- a/greater_tables/gtcore2.py +++ b/greater_tables/gtcore2.py @@ -16,6 +16,7 @@ from pathlib import Path import re import sys from textwrap import wrap +from typing import Optional, Union, Literal import warnings from bs4 import BeautifulSoup @@ -29,6 +30,7 @@ from rich.table import Table from . gtenums import Breakability, Alignment from . gtformats import GT_Format, TableFormat +from . gtconfig import GTConfigModel from . hasher import df_short_hash # turn this fuck-fest off @@ -306,11 +308,11 @@ class GT(object): # self.df.columns.names = [None] * self.df.columns.nlevels self.df_id = df_short_hash(self.df) # TODO: update / change - self.str_table_fmt = str_table_fmt + # self.str_table_fmt = str_table_fmt # TODO: implement - config.table_width_mode = config.table_width_mode.lower() - if config.table_width_mode not in ('explicit', 'natural', 'breakable', 'minimum'): - raise ValueError(f'Inadmissible options {config.table_width_mode} for config.table_width_mode.') + # self.table_width_mode = config.table_width_mode.lower() + # if config.table_width_mode not in ('explicit', 'natural', 'breakable', 'minimum'): + # raise ValueError(f'Inadmissible options {config.table_width_mode} for config.table_width_mode.') # self.table_width_mode = table_width_mode # self.table_width_header_adjust = table_width_header_adjust # self.table_width_header_relax = table_width_header_relax @@ -406,7 +408,7 @@ class GT(object): assert callable( config.default_formatter), 'config.default_formatter must be callable' - def wrapped_config.default_formatter(x): + def wrapped_default_formatter(x): try: return config.default_formatter(x) except ValueError: @@ -1388,7 +1390,7 @@ class GT(object): ) return txt - def make_style(self, config.tabs): + def make_style(self, tabs): """Write out custom CSS for the table.""" if self.config.debug: head_tb = '#0ff' @@ -1797,7 +1799,7 @@ class GT(object): post_process='', label='', latex=None, - config.sparsify=1): + sparsify=1): """ Write DataFrame to custom tikz matrix to allow greater control of formatting and insertion of horizontal and vertical divider lines @@ -2004,7 +2006,7 @@ class GT(object): column_sep=column_sep, row_sep=row_sep, latex=latex, - config.debug=config.debug)) + debug=self.config.debug)) # table header # title rows, start with the empty spacer row @@ -2175,7 +2177,7 @@ class GT(object): return sio.getvalue() @staticmethod - def estimate_column_widths(df, target_width, nc_index, scale, config.equal=False): + def estimate_column_widths(df, target_width, nc_index, scale, equal=False): """ Estimate sensible column widths for the dataframe [in what units?] @@ -2290,7 +2292,7 @@ class GT(object): return colw, tabs @staticmethod - def config.sparsify(df, cs): + def sparsify(df, cs): out = df.copy() for i, c in enumerate(cs): mask = df[cs[:i + 1]].ne(df[cs[:i + 1]].shift()).any(axis=1) @@ -2298,7 +2300,7 @@ class GT(object): return out @staticmethod - def config.sparsify_old(col): + def sparsify_old(col): """ config.sparsify col values, col a pd.Series or dict, with items and accessor column results from a reset_index so has index 0,1,2... this is relied upon. @@ -2320,7 +2322,7 @@ class GT(object): return new_col, rules @staticmethod - def config.sparsify_mi(mi, bottom_level=False): + def sparsify_mi(mi, bottom_level=False): """ as above for a multi index level, without the benefit of the index... really all should use this function diff --git a/scratch.ipynb b/scratch.ipynb index 2bbaeb8..568ee16 100644 --- a/scratch.ipynb +++ b/scratch.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "ce33d474-f3e4-4959-b0d2-9928761f42b0", "metadata": {}, "outputs": [ @@ -22,19 +22,19 @@ "text": [ "The autoreload extension is already loaded. To reload it, use:\n", " %reload_ext autoreload\n", - "time: 1.76 ms (started: 2025-06-12 23:03:06 +01:00)\n" + "time: 1.51 ms (started: 2025-06-12 23:24:35 +01:00)\n" ] } ], "source": [ "%load_ext autotime\n", "%load_ext autoreload \n", - "%autoreload 1" + "%autoreload 2" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 11, "id": "90213338-7d46-4fe8-8925-2bf08e04e483", "metadata": {}, "outputs": [ @@ -42,20 +42,22 @@ "name": "stdout", "output_type": "stream", "text": [ - "time: 385 ms (started: 2025-06-12 23:05:31 +01:00)\n" + "time: 231 ms (started: 2025-06-12 23:27:49 +01:00)\n" ] } ], "source": [ "# %aimport greater_tables.gtconfig\n", - "%aimport greater_tables.testdf\n", + "# %aimport greater_tables.gtcore as gtc\n", + "# %aimport greater_tables.testdf\n", "# import greater_tables.gtconfig as gtc\n", - "import greater_tables.testdf as gtt" + "import greater_tables.testdf as gtt\n", + "import greater_tables.gtcore2 as gtc" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 12, "id": "29c879ca-fa49-47ba-8919-ecee39cdc21b", "metadata": {}, "outputs": [ @@ -63,7 +65,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "time: 125 ms (started: 2025-06-12 23:06:05 +01:00)\n" + "time: 77.2 ms (started: 2025-06-12 23:27:51 +01:00)\n" ] } ], @@ -73,150 +75,51 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "id": "0a5ba2a1-a914-4a63-a175-0997919a48fa", "metadata": {}, "outputs": [ { - "data": { - "text/html": [ - "
| c0 | \n", - "cause administration arrive | \n", - "television four quality | \n", - "
|---|---|---|
| i0 | \n", - "\n", - " | \n", - " |
| 2020-06-24 | \n", - "issue | \n", - "2024-08-17 | \n", - "
| 2020-06-25 | \n", - "hospital account direction | \n", - "2024-08-18 | \n", - "
| 2020-06-26 | \n", - "community create trouble enjoy | \n", - "2024-08-19 | \n", - "
| 2020-06-27 | \n", - "thank although best why month team class admin... | \n", - "2024-08-20 | \n", - "
| 2020-06-28 | \n", - "difference natural discussion report want test | \n", - "2024-08-21 | \n", - "
| 2020-06-29 | \n", - "year structure position poor company word road... | \n", - "2024-08-22 | \n", - "
| 2020-06-30 | \n", - "contain growth response win part enough if pro... | \n", - "2024-08-23 | \n", - "
| 2020-07-01 | \n", - "statement picture cut phone | \n", - "2024-08-24 | \n", - "
| 2020-07-02 | \n", - "perform force remember certainly their least l... | \n", - "2024-08-25 | \n", - "
| 2020-07-03 | \n", - "national common | \n", - "2024-08-26 | \n", - "