From faffd8c8da7aeca6ef35350f93d8bb7a2d289705 Mon Sep 17 00:00:00 2001 From: Bert Palm <bert.palm@ufz.de> Date: Sat, 11 Apr 2020 23:18:05 +0200 Subject: [PATCH] minor improves --- dios/dios.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/dios/dios.py b/dios/dios.py index 0284846..523f77b 100644 --- a/dios/dios.py +++ b/dios/dios.py @@ -354,7 +354,7 @@ class DictOfSeries: locations, just like `series.loc[:]=val` or `df[:]=val` do. Eg. - di1[::2] = di[::3] -> di[::2] + di[::2] = di[::3] -> di[::2] x | x | x | ===== | ==== | ====== | @@ -767,7 +767,7 @@ def pprint_dios(dios, # now data only contains series that we want to print. # if any series exceed max_rows we trim all series to min_rows - series_lengths = data.apply(len) + series_lengths = data.apply(len).to_list() series_maxlen = max(series_lengths) trunc_rows = series_maxlen > max_rows max_rows = min_rows if trunc_rows else series_maxlen @@ -812,7 +812,7 @@ def pprint_dios(dios, # columns. valstr_len = [len(c[0]) for c in outer] - rows = max_rows + 1 # colname + rows = max_rows + 1 # colnames aka. header rows += 1 if trunc_rows else 0 # `...` in rows rows += 1 if header_delim else 0 # underline header @@ -821,10 +821,11 @@ def pprint_dios(dios, colheader = (header_delim * valstr_len[i])[:valstr_len[i]] c.insert(1, colheader) - delim = ' ... ' + dots = ' ... ' if trunc_cols: - outer.insert(max_cols // 2, [delim] * rows) - valstr_len.insert(max_cols // 2, len(delim)) + outer.insert(max_cols // 2, [dots] * rows) + valstr_len.insert(max_cols // 2, len(dots)) + series_lengths.insert(max_cols//2, rows) txt = "" for r in range(rows): @@ -838,17 +839,12 @@ def pprint_dios(dios, # add footer if show_dimensions: - # correction because the collections `series_lengths` - # and `valstr_len` differ by 1 in length. very hacky! - # todo: use a dict/df or dios(?!) to store the str-data - corr = 0 for i, c in enumerate(outer): # ignore the dot-column if trunc_cols and i == max_cols//2: - txt += delim + ' ' * len(col_delim) - corr = 1 + txt += dots + ' ' * len(col_delim) else: - txt += f"[{series_lengths.iat[i-corr]}]".ljust(valstr_len[i] + len(col_delim)) + txt += f"[{series_lengths[i]}]".ljust(valstr_len[i] + len(col_delim)) txt += f'\n\nmax: [{maxlen} rows x {len(dios.columns)} columns]' txt += '\n' -- GitLab