Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT stop using colored in Windows since it does not work #224

Merged
merged 2 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion testing-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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')