From ebdbb42289d7a3d728d005df95ceb63676742d4e Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Fri, 28 Feb 2020 17:39:04 +0100 Subject: [PATCH 1/2] MNT stop using colored in Windows since it does not work --- rampwf/utils/pretty_print.py | 29 +++++++++++++++++++---------- testing-requirements.txt | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/rampwf/utils/pretty_print.py b/rampwf/utils/pretty_print.py index c67d381e..6c999a8f 100644 --- a/rampwf/utils/pretty_print.py +++ b/rampwf/utils/pretty_print.py @@ -2,11 +2,14 @@ """ Utility methods to print the results in a terminal using term colors """ -from __future__ import print_function +import platform from pandas import option_context + from ..externals.colored import stylize, fg, attr +IS_WINDOWS = platform.system() == "Windows" + # Dictionary of term colors used for printing to terminal fg_colors = { 'official_train': 'light_green', @@ -20,12 +23,16 @@ } -def print_title(str): - print(stylize(str, fg(fg_colors['title']) + attr('bold'))) +def print_title(title): + if not IS_WINDOWS: + title = stylize(title, fg(fg_colors['title']) + attr('bold')) + print(title) -def print_warning(str): - print(stylize(str, fg(fg_colors['warning']))) +def print_warning(warning): + if not IS_WINDOWS: + warning = stylize(warning, fg(fg_colors['warning'])) + print(warning) def print_df_scores(df_scores, indent=''): @@ -48,16 +55,18 @@ def print_df_scores(df_scores, indent=''): continue if color_key is None: # table header - line = stylize(line, fg(fg_colors['title']) + attr('bold')) + if not IS_WINDOWS: + line = stylize(line, fg(fg_colors['title']) + attr('bold')) if color_key is not None: tokens = line.split() tokens_bak = tokens[:] if 'official_' + color_key in fg_colors: # line label and official score bold & bright - label_color = fg(fg_colors['official_' + color_key]) - tokens[0] = stylize(tokens[0], label_color + attr('bold')) - tokens[1] = stylize(tokens[1], label_color + attr('bold')) - if color_key in fg_colors: + if not IS_WINDOWS: + label_color = fg(fg_colors['official_' + color_key]) + tokens[0] = stylize(tokens[0], label_color + attr('bold')) + tokens[1] = stylize(tokens[1], label_color + attr('bold')) + if not IS_WINDOWS and (color_key in fg_colors): # other scores pale tokens[2:] = [stylize(token, fg(fg_colors[color_key])) for token in tokens[2:]] diff --git a/testing-requirements.txt b/testing-requirements.txt index 812c433e..ff8cd00b 100644 --- a/testing-requirements.txt +++ b/testing-requirements.txt @@ -10,5 +10,5 @@ xarray scikit-image joblib keras; python_version >= '3.5' or (python_version == '2.7' and sys_platform != 'win32') -tensorflow == 2.0; python_version >= '3.5' or (python_version == '2.7' and sys_platform != 'win32') +tensorflow == 2.0.1; python_version >= '3.5' or (python_version == '2.7' and sys_platform != 'win32') From 98bddb67204ff2cd40a89136ed8e263d4f24ed10 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Fri, 28 Feb 2020 18:02:19 +0100 Subject: [PATCH 2/2] chracters --- rampwf/utils/scoring.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/rampwf/utils/scoring.py b/rampwf/utils/scoring.py index 3c3f148b..a66abe0e 100644 --- a/rampwf/utils/scoring.py +++ b/rampwf/utils/scoring.py @@ -4,6 +4,8 @@ """ import numpy as np import pandas as pd + +from .pretty_print import IS_WINDOWS from .pretty_print import print_warning @@ -53,12 +55,20 @@ def mean_score_matrix(df_scores_list, score_types): precisions = [st.precision for st in score_types] precisions.append(1) # for time # we use unicode no break space so split in print_df_scores works - strs = np.array([[ - u'{val}\u00A0±\u00A0{std}'.format( - val=round(mean, prec), - std=round(std, prec + 1)) - for mean, std, prec in zip(means, stds, precisions)] - for means, stds in zip(meanss, stdss)]) + if not IS_WINDOWS: + strs = np.array([[ + u'{val}\u00A0±\u00A0{std}'.format( + val=round(mean, prec), + std=round(std, prec + 1)) + for mean, std, prec in zip(means, stds, precisions)] + for means, stds in zip(meanss, stdss)]) + else: + strs = np.array([[ + u'{val} +- {std}'.format( + val=round(mean, prec), + std=round(std, prec + 1)) + for mean, std, prec in zip(means, stds, precisions)] + for means, stds in zip(meanss, stdss)]) df_scores = pd.DataFrame( strs, columns=df_scores_list[0].columns, index=df_scores_list[0].index) return df_scores