Skip to content

Commit

Permalink
MNT stop using colored in Windows since it does not work (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
glemaitre committed Feb 28, 2020
1 parent 8b6b6c2 commit 718350d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
29 changes: 19 additions & 10 deletions rampwf/utils/pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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=''):
Expand All @@ -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:]]
Expand Down
22 changes: 16 additions & 6 deletions rampwf/utils/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
import numpy as np
import pandas as pd

from .pretty_print import IS_WINDOWS
from .pretty_print import print_warning


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 718350d

Please sign in to comment.