From 796dce20480044ed03f51af3721215fafdd919a5 Mon Sep 17 00:00:00 2001 From: jos Date: Sun, 10 Jan 2016 11:30:24 -0500 Subject: [PATCH] Change all strings to unicode --- pandas_profiling/__init__.py | 5 ++--- pandas_profiling/formatters.py | 6 +++--- pandas_profiling/templates.py | 32 ++++++++++++++++---------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/pandas_profiling/__init__.py b/pandas_profiling/__init__.py index ba81e2bd0..3b46874b6 100644 --- a/pandas_profiling/__init__.py +++ b/pandas_profiling/__init__.py @@ -247,20 +247,19 @@ def format_row(freq, label, extra_class=''): overview_html = templates.overview_template.format({k: fmt(v, k) for k, v in stats_object['table'].iteritems()}) # Variables - rows_html = "" + rows_html = u"" for idx, row in stats_object['variables'].iterrows(): formatted_values = {'varname': idx, 'varid': hash(idx)} for col, value in row.iteritems(): - formatted_values[col] = fmt(value, col) + formatted_values[col] = unicode(fmt(value, col)) if row['type'] == 'CAT': formatted_values['minifreqtable'] = freq_table(stats_object['freq'][idx], stats_object['table']['n'], templates.mini_freq_table, templates.mini_freq_table_row, 3) formatted_values['freqtable'] = freq_table(stats_object['freq'][idx], stats_object['table']['n'], templates.freq_table, templates.freq_table_row, 20) - rows_html += templates.row_templates_dict[row['type']].format(formatted_values) # Sample diff --git a/pandas_profiling/formatters.py b/pandas_profiling/formatters.py index 094998d07..186a6cf1d 100644 --- a/pandas_profiling/formatters.py +++ b/pandas_profiling/formatters.py @@ -8,10 +8,10 @@ def LerpColour(c1,c2,t): def fmt_color(text, color): - return('{text}'.format(color=color,text=str(text))) + return(u'{text}'.format(color=color,text=str(text))) def fmt_class(text, cls): - return('{text}'.format(cls=cls,text=str(text))) + return(u'{text}'.format(cls=cls,text=str(text))) def fmt_bytesize(num, suffix='B'): for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']: @@ -25,7 +25,7 @@ def fmt_percent(v): formatters={ u'freq': (lambda v: gradient_format(v, 0, 62000, (30, 198, 244), (99, 200, 72))), - u'p_missing': lambda v: fmt_class("0%", "notimportant") if v == 0 else "{:2.1f}%".format(v*100), + u'p_missing': lambda v: fmt_class(u"0%", "notimportant") if v == 0 else "{:2.1f}%".format(v*100), u'p_unique': fmt_percent, u'p_zeroes': fmt_percent , u'memorysize': fmt_bytesize, diff --git a/pandas_profiling/templates.py b/pandas_profiling/templates.py index 0ef4ce3fd..ee960b9f0 100644 --- a/pandas_profiling/templates.py +++ b/pandas_profiling/templates.py @@ -1,4 +1,4 @@ -base_html=''' +base_html=u''' @@ -52,7 +52,7 @@ font-weight: 600; } - .stats tr{ + .stats tr { border: 0; } @@ -213,7 +213,7 @@ ''' -wrapper_html = ''' +wrapper_html = u''' @@ -240,7 +240,7 @@ ''' -sample_html = ''' +sample_html = u'''
{sample_table_html} @@ -289,21 +289,21 @@
''' -_row_header = '''
+_row_header = u'''

{varname}
{vartype}

''' -_row_header_ignore = '''
+_row_header_ignore = u'''

{varname}
{vartype}

''' -_row_footer = '''
''' +_row_footer = u'''
''' row_templates_dict = {} -row_templates_dict['NUM'] = _row_header.format(vartype="Numeric", varname="{0[varname]}") + ''' +row_templates_dict['NUM'] = _row_header.format(vartype="Numeric", varname="{0[varname]}") + u'''
@@ -394,7 +394,7 @@
''' + _row_footer -row_templates_dict['DATE'] = _row_header.format(vartype="Date", varname="{0[varname]}") + ''' +row_templates_dict['DATE'] = _row_header.format(vartype="Date", varname="{0[varname]}") + u'''
@@ -426,7 +426,7 @@ row_templates_dict['DISCRETE'] = row_templates_dict['NUM'] -row_templates_dict['CAT'] = _row_header.format(vartype="Categorical, low cardinality", varname="{0[varname]}") + ''' +row_templates_dict['CAT'] = _row_header.format(vartype="Categorical, low cardinality", varname="{0[varname]}") + u'''
@@ -453,7 +453,7 @@ {0[freqtable]} ''' + _row_footer -row_templates_dict['UNIQUE'] = _row_header.format(vartype="Unique ID", varname="{0[varname]}") + ''' +row_templates_dict['UNIQUE'] = _row_header.format(vartype="Unique ID", varname="{0[varname]}") + u'''
@@ -470,7 +470,7 @@
Example values
''' + _row_footer -row_templates_dict['CONST'] = _row_header_ignore.format(vartype="Constant", varname="{0[varname]}") + ''' +row_templates_dict['CONST'] = _row_header_ignore.format(vartype="Constant", varname="{0[varname]}") + u'''

This variable is constant and should be ignored for analysis

@@ -484,14 +484,14 @@ ''' + _row_footer -mini_freq_table = ''' +mini_freq_table = u'''
{rows}
''' -mini_freq_table_row = ''' +mini_freq_table_row = u''' {label}
@@ -501,7 +501,7 @@ ''' -freq_table = ''' +freq_table = u'''
@@ -518,7 +518,7 @@ ''' -freq_table_row = ''' +freq_table_row = u'''
{label} {count}