11
11
from pandas .core .common import adjoin , isnull , notnull
12
12
from pandas .core .index import MultiIndex , _ensure_index
13
13
from pandas .util import py3compat
14
-
14
+ from pandas .core .config import get_option , set_option , \
15
+ reset_options
15
16
import pandas .core .common as com
16
17
import pandas .lib as lib
17
18
@@ -69,7 +70,7 @@ def __init__(self, series, buf=None, header=True, length=True,
69
70
self .header = header
70
71
71
72
if float_format is None :
72
- float_format = print_config .float_format
73
+ float_format = get_option ( " print_config.float_format" )
73
74
self .float_format = float_format
74
75
75
76
def _get_footer (self ):
@@ -145,11 +146,11 @@ def to_string(self):
145
146
_strlen = len
146
147
else :
147
148
def _encode_diff (x ):
148
- return len (x ) - len (x .decode (print_config .encoding ))
149
+ return len (x ) - len (x .decode (get_option ( " print_config.encoding" ) ))
149
150
150
151
def _strlen (x ):
151
152
try :
152
- return len (x .decode (print_config .encoding ))
153
+ return len (x .decode (get_option ( " print_config.encoding" ) ))
153
154
except UnicodeError :
154
155
return len (x )
155
156
@@ -176,7 +177,7 @@ def __init__(self, frame, buf=None, columns=None, col_space=None,
176
177
self .show_index_names = index_names
177
178
178
179
if sparsify is None :
179
- sparsify = print_config .multi_sparse
180
+ sparsify = get_option ( " print_config.multi_sparse" )
180
181
181
182
self .sparsify = sparsify
182
183
@@ -188,7 +189,7 @@ def __init__(self, frame, buf=None, columns=None, col_space=None,
188
189
self .index = index
189
190
190
191
if justify is None :
191
- self .justify = print_config .colheader_justify
192
+ self .justify = get_option ( " print_config.colheader_justify" )
192
193
else :
193
194
self .justify = justify
194
195
@@ -697,13 +698,13 @@ def format_array(values, formatter, float_format=None, na_rep='NaN',
697
698
fmt_klass = GenericArrayFormatter
698
699
699
700
if space is None :
700
- space = print_config .column_space
701
+ space = get_option ( " print_config.column_space" )
701
702
702
703
if float_format is None :
703
- float_format = print_config .float_format
704
+ float_format = get_option ( " print_config.float_format" )
704
705
705
706
if digits is None :
706
- digits = print_config .precision
707
+ digits = get_option ( " print_config.precision" )
707
708
708
709
fmt_obj = fmt_klass (values , digits , na_rep = na_rep ,
709
710
float_format = float_format ,
@@ -739,9 +740,9 @@ def _have_unicode(self):
739
740
740
741
def _format_strings (self , use_unicode = False ):
741
742
if self .float_format is None :
742
- float_format = print_config .float_format
743
+ float_format = get_option ( " print_config.float_format" )
743
744
if float_format is None :
744
- fmt_str = '%% .%dg' % print_config .precision
745
+ fmt_str = '%% .%dg' % get_option ( " print_config.precision" )
745
746
float_format = lambda x : fmt_str % x
746
747
else :
747
748
float_format = self .float_format
@@ -863,7 +864,7 @@ def _make_fixed_width(strings, justify='right', minimum=None):
863
864
if minimum is not None :
864
865
max_len = max (minimum , max_len )
865
866
866
- conf_max = print_config .max_colwidth
867
+ conf_max = get_option ( " print_config.max_colwidth" )
867
868
if conf_max is not None and max_len > conf_max :
868
869
max_len = conf_max
869
870
@@ -974,34 +975,56 @@ def set_printoptions(precision=None, column_space=None, max_rows=None,
974
975
elements in outer levels within groups)
975
976
"""
976
977
if precision is not None :
977
- print_config .precision = precision
978
+ set_option ( " print_config.precision" , precision )
978
979
if column_space is not None :
979
- print_config .column_space = column_space
980
+ set_option ( " print_config.column_space" , column_space )
980
981
if max_rows is not None :
981
- print_config .max_rows = max_rows
982
+ set_option ( " print_config.max_rows" , max_rows )
982
983
if max_colwidth is not None :
983
- print_config .max_colwidth = max_colwidth
984
+ set_option ( " print_config.max_colwidth" , max_colwidth )
984
985
if max_columns is not None :
985
- print_config .max_columns = max_columns
986
+ set_option ( " print_config.max_columns" , max_columns )
986
987
if colheader_justify is not None :
987
- print_config .colheader_justify = colheader_justify
988
+ set_option ( " print_config.colheader_justify" , colheader_justify )
988
989
if notebook_repr_html is not None :
989
- print_config .notebook_repr_html = notebook_repr_html
990
+ set_option ( " print_config.notebook_repr_html" , notebook_repr_html )
990
991
if date_dayfirst is not None :
991
- print_config .date_dayfirst = date_dayfirst
992
+ set_option ( " print_config.date_dayfirst" , date_dayfirst )
992
993
if date_yearfirst is not None :
993
- print_config .date_yearfirst = date_yearfirst
994
+ set_option ( " print_config.date_yearfirst" , date_yearfirst )
994
995
if pprint_nest_depth is not None :
995
- print_config .pprint_nest_depth = pprint_nest_depth
996
+ set_option ( " print_config.pprint_nest_depth" , pprint_nest_depth )
996
997
if multi_sparse is not None :
997
- print_config .multi_sparse = multi_sparse
998
+ set_option ( " print_config.multi_sparse" , multi_sparse )
998
999
if encoding is not None :
999
- print_config .encoding = encoding
1000
-
1000
+ set_option ("print_config.encoding" , encoding )
1001
1001
1002
1002
def reset_printoptions ():
1003
- print_config .reset ()
1003
+ reset_options ("print_config." )
1004
+
1005
+ def detect_console_encoding ():
1006
+ """
1007
+ Try to find the most capable encoding supported by the console.
1008
+ slighly modified from the way IPython handles the same issue.
1009
+ """
1010
+ import locale
1011
+
1012
+ encoding = None
1013
+ try :
1014
+ encoding = sys .stdin .encoding
1015
+ except AttributeError :
1016
+ pass
1004
1017
1018
+ if not encoding or encoding == 'ascii' : # try again for something better
1019
+ try :
1020
+ encoding = locale .getpreferredencoding ()
1021
+ except Exception :
1022
+ pass
1023
+
1024
+ if not encoding : # when all else fails. this will usually be "ascii"
1025
+ encoding = sys .getdefaultencoding ()
1026
+
1027
+ return encoding
1005
1028
1006
1029
class EngFormatter (object ):
1007
1030
"""
@@ -1109,59 +1132,8 @@ def set_eng_float_format(precision=None, accuracy=3, use_eng_prefix=False):
1109
1132
"being renamed to 'accuracy'" , FutureWarning )
1110
1133
accuracy = precision
1111
1134
1112
- print_config .float_format = EngFormatter (accuracy , use_eng_prefix )
1113
- print_config .column_space = max (12 , accuracy + 9 )
1114
-
1115
-
1116
- class _GlobalPrintConfig (object ):
1117
- """
1118
- Holds the console formatting settings for DataFrame and friends
1119
- """
1120
-
1121
- def __init__ (self ):
1122
- self .precision = self .digits = 7
1123
- self .float_format = None
1124
- self .column_space = 12
1125
- self .max_rows = 200
1126
- self .max_colwidth = 50
1127
- self .max_columns = 0
1128
- self .colheader_justify = 'right'
1129
- self .notebook_repr_html = True
1130
- self .date_dayfirst = False
1131
- self .date_yearfirst = False
1132
- self .pprint_nest_depth = 3
1133
- self .multi_sparse = True
1134
- self .encoding = self .detect_encoding ()
1135
-
1136
- def detect_encoding (self ):
1137
- """
1138
- Try to find the most capable encoding supported by the console.
1139
- slighly modified from the way IPython handles the same issue.
1140
- """
1141
- import locale
1142
-
1143
- encoding = None
1144
- try :
1145
- encoding = sys .stdin .encoding
1146
- except AttributeError :
1147
- pass
1148
-
1149
- if not encoding or encoding == 'ascii' : # try again for better
1150
- try :
1151
- encoding = locale .getpreferredencoding ()
1152
- except Exception :
1153
- pass
1154
-
1155
- if not encoding : # when all else fails. this will usually be "ascii"
1156
- encoding = sys .getdefaultencoding ()
1157
-
1158
- return encoding
1159
-
1160
- def reset (self ):
1161
- self .__init__ ()
1162
-
1163
- print_config = _GlobalPrintConfig ()
1164
-
1135
+ set_option ("print_config.float_format" , EngFormatter (accuracy , use_eng_prefix ))
1136
+ set_option ("print_config.column_space" , max (12 , accuracy + 9 ))
1165
1137
1166
1138
def _put_lines (buf , lines ):
1167
1139
if any (isinstance (x , unicode ) for x in lines ):
0 commit comments