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/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