From 3442bf22a5c3739fd636bfafee142bdabdea52c0 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Thu, 11 Mar 2021 09:27:30 +0100 Subject: [PATCH] CLN: reorganise/group variables for readability --- pandas/io/formats/style.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index ec09a4cc4cd89..5344d1d8487e6 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -350,12 +350,6 @@ def _translate(self): Convert the DataFrame in `self.data` and the attrs from `_build_styles` into a dictionary of {head, body, uuid, cellstyle}. """ - table_styles = self.table_styles or [] - caption = self.caption - ctx = self.ctx - hidden_index = self.hidden_index - hidden_columns = self.hidden_columns - uuid = self.uuid ROW_HEADING_CLASS = "row_heading" COL_HEADING_CLASS = "col_heading" INDEX_NAME_CLASS = "index_name" @@ -364,12 +358,22 @@ def _translate(self): BLANK_CLASS = "blank" BLANK_VALUE = "" + # mapping variables + ctx = self.ctx # td css styles from apply() and applymap() + cell_context = self.cell_context # td css classes from set_td_classes() + cellstyle_map: DefaultDict[Tuple[CSSPair, ...], List[str]] = defaultdict(list) + + # copied attributes + table_styles = self.table_styles or [] + caption = self.caption + hidden_index = self.hidden_index + hidden_columns = self.hidden_columns + uuid = self.uuid + # for sparsifying a MultiIndex idx_lengths = _get_level_lengths(self.index) col_lengths = _get_level_lengths(self.columns, hidden_columns) - cell_context = self.cell_context - n_rlvls = self.data.index.nlevels n_clvls = self.data.columns.nlevels rlabels = self.data.index.tolist() @@ -381,10 +385,7 @@ def _translate(self): clabels = [[x] for x in clabels] clabels = list(zip(*clabels)) - cellstyle_map: DefaultDict[Tuple[CSSPair, ...], List[str]] = defaultdict(list) - head = [] - for r in range(n_clvls): # Blank for Index columns... row_es = [