Python pandas.core.config.get_option() Examples
The following are 30
code examples of pandas.core.config.get_option().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.core.config
, or try the search function
.
Example #1
Source File: test_excel.py From recruit with Apache License 2.0 | 6 votes |
def set_engine_and_path(self, request, merge_cells, engine, ext): """Fixture to set engine and open file for use in each test case Rather than requiring `engine=...` to be provided explicitly as an argument in each test, this fixture sets a global option to dictate which engine should be used to write Excel files. After executing the test it rolls back said change to the global option. It also uses a context manager to open a temporary excel file for the function to write to, accessible via `self.path` Notes ----- This fixture will run as part of each test method defined in the class and any subclasses, on account of the `autouse=True` argument """ option_name = 'io.excel.{ext}.writer'.format(ext=ext.strip('.')) prev_engine = get_option(option_name) set_option(option_name, engine) with ensure_clean(ext) as path: self.path = path yield set_option(option_name, prev_engine) # Roll back option change
Example #2
Source File: excel.py From vnpy_crypto with MIT License | 6 votes |
def __new__(cls, path, engine=None, **kwargs): # only switch class if generic(ExcelWriter) if issubclass(cls, ExcelWriter): if engine is None or (isinstance(engine, string_types) and engine == 'auto'): if isinstance(path, string_types): ext = os.path.splitext(path)[-1][1:] else: ext = 'xlsx' try: engine = config.get_option('io.excel.{ext}.writer' .format(ext=ext)) if engine == 'auto': engine = _get_default_writer(ext) except KeyError: error = ValueError("No engine for filetype: '{ext}'" .format(ext=ext)) raise error cls = get_writer(engine) return object.__new__(cls) # declare external properties you can count on
Example #3
Source File: config_init.py From Computable with MIT License | 6 votes |
def mpl_style_cb(key): import sys from pandas.tools.plotting import mpl_stylesheet global style_backup val = cf.get_option(key) if 'matplotlib' not in sys.modules.keys(): if not(val): # starting up, we get reset to None return val raise Exception("matplotlib has not been imported. aborting") import matplotlib.pyplot as plt if val == 'default': style_backup = dict([(k, plt.rcParams[k]) for k in mpl_stylesheet]) plt.rcParams.update(mpl_stylesheet) elif not val: if style_backup: plt.rcParams.update(style_backup) return val
Example #4
Source File: index.py From Computable with MIT License | 6 votes |
def __repr__(self): encoding = get_option('display.encoding') attrs = [('levels', default_pprint(self.levels)), ('labels', default_pprint(self.labels))] if not all(name is None for name in self.names): attrs.append(('names', default_pprint(self.names))) if self.sortorder is not None: attrs.append(('sortorder', default_pprint(self.sortorder))) space = ' ' * (len(self.__class__.__name__) + 1) prepr = (u(",\n%s") % space).join([u("%s=%s") % (k, v) for k, v in attrs]) res = u("%s(%s)") % (self.__class__.__name__, prepr) if not compat.PY3: # needs to be str in Python 2 res = res.encode(encoding) return res
Example #5
Source File: excel.py From recruit with Apache License 2.0 | 6 votes |
def __new__(cls, path, engine=None, **kwargs): # only switch class if generic(ExcelWriter) if issubclass(cls, ExcelWriter): if engine is None or (isinstance(engine, string_types) and engine == 'auto'): if isinstance(path, string_types): ext = os.path.splitext(path)[-1][1:] else: ext = 'xlsx' try: engine = config.get_option('io.excel.{ext}.writer' .format(ext=ext)) if engine == 'auto': engine = _get_default_writer(ext) except KeyError: error = ValueError("No engine for filetype: '{ext}'" .format(ext=ext)) raise error cls = get_writer(engine) return object.__new__(cls) # declare external properties you can count on
Example #6
Source File: format.py From recruit with Apache License 2.0 | 6 votes |
def __init__(self, series, buf=None, length=True, header=True, index=True, na_rep='NaN', name=False, float_format=None, dtype=True, max_rows=None): self.series = series self.buf = buf if buf is not None else StringIO() self.name = name self.na_rep = na_rep self.header = header self.length = length self.index = index self.max_rows = max_rows if float_format is None: float_format = get_option("display.float_format") self.float_format = float_format self.dtype = dtype self.adj = _get_adjustment() self._chk_truncate()
Example #7
Source File: test_excel.py From vnpy_crypto with MIT License | 6 votes |
def set_engine_and_path(self, request, merge_cells, engine, ext): """Fixture to set engine and open file for use in each test case Rather than requiring `engine=...` to be provided explicitly as an argument in each test, this fixture sets a global option to dictate which engine should be used to write Excel files. After executing the test it rolls back said change to the global option. It also uses a context manager to open a temporary excel file for the function to write to, accessible via `self.path` Notes ----- This fixture will run as part of each test method defined in the class and any subclasses, on account of the `autouse=True` argument """ option_name = 'io.excel.{ext}.writer'.format(ext=ext.strip('.')) prev_engine = get_option(option_name) set_option(option_name, engine) with ensure_clean(ext) as path: self.path = path yield set_option(option_name, prev_engine) # Roll back option change
Example #8
Source File: printing.py From recruit with Apache License 2.0 | 6 votes |
def format_object_attrs(obj): """ Return a list of tuples of the (attr, formatted_value) for common attrs, including dtype, name, length Parameters ---------- obj : object must be iterable Returns ------- list """ attrs = [] if hasattr(obj, 'dtype'): attrs.append(('dtype', "'{}'".format(obj.dtype))) if getattr(obj, 'name', None) is not None: attrs.append(('name', default_pprint(obj.name))) max_seq_items = get_option('display.max_seq_items') or len(obj) if len(obj) > max_seq_items: attrs.append(('length', len(obj))) return attrs
Example #9
Source File: categorical.py From vnpy_crypto with MIT License | 6 votes |
def _repr_categories(self): """ return the base repr for the categories """ max_categories = (10 if get_option("display.max_categories") == 0 else get_option("display.max_categories")) from pandas.io.formats import format as fmt if len(self.categories) > max_categories: num = max_categories // 2 head = fmt.format_array(self.categories[:num], None) tail = fmt.format_array(self.categories[-num:], None) category_strs = head + ["..."] + tail else: category_strs = fmt.format_array(self.categories, None) # Strip all leading spaces, which format_array adds for columns... category_strs = [x.strip() for x in category_strs] return category_strs
Example #10
Source File: series.py From recruit with Apache License 2.0 | 6 votes |
def __unicode__(self): """ Return a string representation for a particular DataFrame. Invoked by unicode(df) in py2 only. Yields a Unicode String in both py2/py3. """ buf = StringIO(u("")) width, height = get_terminal_size() max_rows = (height if get_option("display.max_rows") == 0 else get_option("display.max_rows")) show_dimensions = get_option("display.show_dimensions") self.to_string(buf=buf, name=self.name, dtype=self.dtype, max_rows=max_rows, length=show_dimensions) result = buf.getvalue() return result
Example #11
Source File: format.py From vnpy_crypto with MIT License | 6 votes |
def __init__(self, series, buf=None, length=True, header=True, index=True, na_rep='NaN', name=False, float_format=None, dtype=True, max_rows=None): self.series = series self.buf = buf if buf is not None else StringIO() self.name = name self.na_rep = na_rep self.header = header self.length = length self.index = index self.max_rows = max_rows if float_format is None: float_format = get_option("display.float_format") self.float_format = float_format self.dtype = dtype self.adj = _get_adjustment() self._chk_truncate()
Example #12
Source File: category.py From vnpy_crypto with MIT License | 6 votes |
def _format_attrs(self): """ Return a list of tuples of the (attr,formatted_value) """ max_categories = (10 if get_option("display.max_categories") == 0 else get_option("display.max_categories")) attrs = [ ('categories', ibase.default_pprint(self.categories, max_seq_items=max_categories)), ('ordered', self.ordered)] if self.name is not None: attrs.append(('name', ibase.default_pprint(self.name))) attrs.append(('dtype', "'%s'" % self.dtype.name)) max_seq_items = get_option('display.max_seq_items') or len(self) if len(self) > max_seq_items: attrs.append(('length', len(self))) return attrs
Example #13
Source File: html.py From vnpy_crypto with MIT License | 6 votes |
def __init__(self, formatter, classes=None, max_rows=None, max_cols=None, notebook=False, border=None, table_id=None): self.fmt = formatter self.classes = classes self.frame = self.fmt.frame self.columns = self.fmt.tr_frame.columns self.elements = [] self.bold_rows = self.fmt.kwds.get('bold_rows', False) self.escape = self.fmt.kwds.get('escape', True) self.max_rows = max_rows or len(self.fmt.frame) self.max_cols = max_cols or len(self.fmt.columns) self.show_dimensions = self.fmt.show_dimensions self.is_truncated = (self.max_rows < len(self.fmt.frame) or self.max_cols < len(self.fmt.columns)) self.notebook = notebook if border is None: border = get_option('display.html.border') self.border = border self.table_id = table_id
Example #14
Source File: categorical.py From recruit with Apache License 2.0 | 6 votes |
def _repr_categories(self): """ return the base repr for the categories """ max_categories = (10 if get_option("display.max_categories") == 0 else get_option("display.max_categories")) from pandas.io.formats import format as fmt if len(self.categories) > max_categories: num = max_categories // 2 head = fmt.format_array(self.categories[:num], None) tail = fmt.format_array(self.categories[-num:], None) category_strs = head + ["..."] + tail else: category_strs = fmt.format_array(self.categories, None) # Strip all leading spaces, which format_array adds for columns... category_strs = [x.strip() for x in category_strs] return category_strs
Example #15
Source File: missing.py From vnpy_crypto with MIT License | 6 votes |
def _use_inf_as_na(key): """Option change callback for na/inf behaviour Choose which replacement for numpy.isnan / -numpy.isfinite is used. Parameters ---------- flag: bool True means treat None, NaN, INF, -INF as null (old way), False means None and NaN are null, but INF, -INF are not null (new way). Notes ----- This approach to setting global module values is discussed and approved here: * http://stackoverflow.com/questions/4859217/ programmatically-creating-variables-in-python/4859312#4859312 """ from pandas.core.config import get_option flag = get_option(key) if flag: globals()['_isna'] = _isna_old else: globals()['_isna'] = _isna_new
Example #16
Source File: common.py From Computable with MIT License | 6 votes |
def _pprint_dict(seq, _nest_lvl=0, **kwds): """ internal. pprinter for iterables. you should probably use pprint_thing() rather then calling this directly. """ fmt = u("{%s}") pairs = [] pfmt = u("%s: %s") nitems = get_option("max_seq_items") or len(seq) for k, v in list(seq.items())[:nitems]: pairs.append(pfmt % (pprint_thing(k, _nest_lvl + 1, **kwds), pprint_thing(v, _nest_lvl + 1, **kwds))) if nitems < len(seq): return fmt % (", ".join(pairs) + ", ...") else: return fmt % ", ".join(pairs)
Example #17
Source File: common.py From Computable with MIT License | 6 votes |
def _use_inf_as_null(key): """Option change callback for null/inf behaviour Choose which replacement for numpy.isnan / -numpy.isfinite is used. Parameters ---------- flag: bool True means treat None, NaN, INF, -INF as null (old way), False means None and NaN are null, but INF, -INF are not null (new way). Notes ----- This approach to setting global module values is discussed and approved here: * http://stackoverflow.com/questions/4859217/ programmatically-creating-variables-in-python/4859312#4859312 """ flag = get_option(key) if flag: globals()['_isnull'] = _isnull_old else: globals()['_isnull'] = _isnull_new
Example #18
Source File: missing.py From recruit with Apache License 2.0 | 6 votes |
def _use_inf_as_na(key): """Option change callback for na/inf behaviour Choose which replacement for numpy.isnan / -numpy.isfinite is used. Parameters ---------- flag: bool True means treat None, NaN, INF, -INF as null (old way), False means None and NaN are null, but INF, -INF are not null (new way). Notes ----- This approach to setting global module values is discussed and approved here: * http://stackoverflow.com/questions/4859217/ programmatically-creating-variables-in-python/4859312#4859312 """ from pandas.core.config import get_option flag = get_option(key) if flag: globals()['_isna'] = _isna_old else: globals()['_isna'] = _isna_new
Example #19
Source File: printing.py From vnpy_crypto with MIT License | 5 votes |
def _pprint_seq(seq, _nest_lvl=0, max_seq_items=None, **kwds): """ internal. pprinter for iterables. you should probably use pprint_thing() rather then calling this directly. bounds length of printed sequence, depending on options """ if isinstance(seq, set): fmt = u("{{{body}}}") else: fmt = u("[{body}]") if hasattr(seq, '__setitem__') else u("({body})") if max_seq_items is False: nitems = len(seq) else: nitems = max_seq_items or get_option("max_seq_items") or len(seq) s = iter(seq) r = [] for i in range(min(nitems, len(seq))): # handle sets, no slicing r.append(pprint_thing( next(s), _nest_lvl + 1, max_seq_items=max_seq_items, **kwds)) body = ", ".join(r) if nitems < len(seq): body += ", ..." elif isinstance(seq, tuple) and len(seq) == 1: body += ',' return fmt.format(body=body)
Example #20
Source File: dtypes.py From vnpy_crypto with MIT License | 5 votes |
def __bytes__(self): """ Return a string representation for a particular object. Invoked by bytes(obj) in py3 only. Yields a bytestring in both py2/py3. """ from pandas.core.config import get_option encoding = get_option("display.encoding") return self.__unicode__().encode(encoding, 'replace')
Example #21
Source File: format.py From vnpy_crypto with MIT License | 5 votes |
def __init__(self): super(EastAsianTextAdjustment, self).__init__() if get_option("display.unicode.ambiguous_as_wide"): self.ambiguous_width = 2 else: self.ambiguous_width = 1
Example #22
Source File: printing.py From vnpy_crypto with MIT License | 5 votes |
def _pprint_dict(seq, _nest_lvl=0, max_seq_items=None, **kwds): """ internal. pprinter for iterables. you should probably use pprint_thing() rather then calling this directly. """ fmt = u("{{{things}}}") pairs = [] pfmt = u("{key}: {val}") if max_seq_items is False: nitems = len(seq) else: nitems = max_seq_items or get_option("max_seq_items") or len(seq) for k, v in list(seq.items())[:nitems]: pairs.append( pfmt.format( key=pprint_thing(k, _nest_lvl + 1, max_seq_items=max_seq_items, **kwds), val=pprint_thing(v, _nest_lvl + 1, max_seq_items=max_seq_items, **kwds))) if nitems < len(seq): return fmt.format(things=", ".join(pairs) + ", ...") else: return fmt.format(things=", ".join(pairs))
Example #23
Source File: format.py From vnpy_crypto with MIT License | 5 votes |
def _get_adjustment(): use_east_asian_width = get_option("display.unicode.east_asian_width") if use_east_asian_width: return EastAsianTextAdjustment() else: return TextAdjustment()
Example #24
Source File: config_init.py From vnpy_crypto with MIT License | 5 votes |
def register_converter_cb(key): from pandas.plotting import register_matplotlib_converters from pandas.plotting import deregister_matplotlib_converters if cf.get_option(key): register_matplotlib_converters() else: deregister_matplotlib_converters()
Example #25
Source File: base.py From vnpy_crypto with MIT License | 5 votes |
def __bytes__(self): """ Return a string representation for a particular object. Invoked by bytes(obj) in py3 only. Yields a bytestring in both py2/py3. """ from pandas.core.config import get_option encoding = get_option("display.encoding") return self.__unicode__().encode(encoding, 'replace')
Example #26
Source File: format.py From vnpy_crypto with MIT License | 5 votes |
def format_array(values, formatter, float_format=None, na_rep='NaN', digits=None, space=None, justify='right', decimal='.'): if is_categorical_dtype(values): fmt_klass = CategoricalArrayFormatter elif is_interval_dtype(values): fmt_klass = IntervalArrayFormatter elif is_float_dtype(values.dtype): fmt_klass = FloatArrayFormatter elif is_period_arraylike(values): fmt_klass = PeriodArrayFormatter elif is_integer_dtype(values.dtype): fmt_klass = IntArrayFormatter elif is_datetimetz(values): fmt_klass = Datetime64TZFormatter elif is_datetime64_dtype(values.dtype): fmt_klass = Datetime64Formatter elif is_timedelta64_dtype(values.dtype): fmt_klass = Timedelta64Formatter else: fmt_klass = GenericArrayFormatter if space is None: space = get_option("display.column_space") if float_format is None: float_format = get_option("display.float_format") if digits is None: digits = get_option("display.precision") fmt_obj = fmt_klass(values, digits=digits, na_rep=na_rep, float_format=float_format, formatter=formatter, space=space, justify=justify, decimal=decimal) return fmt_obj.get_result()
Example #27
Source File: format.py From Computable with MIT License | 5 votes |
def _make_fixed_width(strings, justify='right', minimum=None, truncated=False): if len(strings) == 0 or justify == 'all': return strings _strlen = _strlen_func() max_len = np.max([_strlen(x) for x in strings]) if minimum is not None: max_len = max(minimum, max_len) conf_max = get_option("display.max_colwidth") if conf_max is not None and max_len > conf_max: max_len = conf_max if justify == 'left': justfunc = lambda self, x: self.ljust(x) else: justfunc = lambda self, x: self.rjust(x) def just(x): eff_len = max_len if conf_max is not None: if (conf_max > 3) & (_strlen(x) > max_len): x = x[:eff_len - 3] + '...' return justfunc(x, eff_len) result = [just(x) for x in strings] if truncated: result.append(justfunc('...'[:max_len], max_len)) return result
Example #28
Source File: format.py From Computable with MIT License | 5 votes |
def get_console_size(): """Return console size as tuple = (width, height). Returns (None,None) in non-interactive session. """ display_width = get_option('display.width') # deprecated. display_height = get_option('display.height', silent=True) # Consider # interactive shell terminal, can detect term size # interactive non-shell terminal (ipnb/ipqtconsole), cannot detect term # size non-interactive script, should disregard term size # in addition # width,height have default values, but setting to 'None' signals # should use Auto-Detection, But only in interactive shell-terminal. # Simple. yeah. if com.in_interactive_session(): if com.in_ipython_frontend(): # sane defaults for interactive non-shell terminal # match default for width,height in config_init from pandas.core.config import get_default_val terminal_width = get_default_val('display.width') terminal_height = get_default_val('display.height') else: # pure terminal terminal_width, terminal_height = get_terminal_size() else: terminal_width, terminal_height = None, None # Note if the User sets width/Height to None (auto-detection) # and we're in a script (non-inter), this will return (None,None) # caller needs to deal. return (display_width or terminal_width, display_height or terminal_height)
Example #29
Source File: common.py From Computable with MIT License | 5 votes |
def _get_handle(path, mode, encoding=None, compression=None): """Gets file handle for given path and mode. NOTE: Under Python 3.2, getting a compressed file handle means reading in the entire file, decompressing it and decoding it to ``str`` all at once and then wrapping it in a StringIO. """ if compression is not None: if encoding is not None and not compat.PY3: msg = 'encoding + compression not yet supported in Python 2' raise ValueError(msg) if compression == 'gzip': import gzip f = gzip.GzipFile(path, 'rb') elif compression == 'bz2': import bz2 f = bz2.BZ2File(path, 'rb') else: raise ValueError('Unrecognized compression type: %s' % compression) if compat.PY3_2: # gzip and bz2 don't work with TextIOWrapper in 3.2 encoding = encoding or get_option('display.encoding') f = StringIO(f.read().decode(encoding)) elif compat.PY3: from io import TextIOWrapper f = TextIOWrapper(f, encoding=encoding) return f else: if compat.PY3: if encoding: f = open(path, mode, encoding=encoding) else: f = open(path, mode, errors='replace') else: f = open(path, mode) return f
Example #30
Source File: format.py From Computable with MIT License | 5 votes |
def _format_strings(self): if self.float_format is None: float_format = get_option("display.float_format") if float_format is None: fmt_str = '%% .%dg' % get_option("display.precision") float_format = lambda x: fmt_str % x else: float_format = self.float_format formatter = self.formatter if self.formatter is not None else \ (lambda x: com.pprint_thing(x, escape_chars=('\t', '\r', '\n'))) def _format(x): if self.na_rep is not None and lib.checknull(x): if x is None: return 'None' return self.na_rep elif isinstance(x, PandasObject): return '%s' % x else: # object dtype return '%s' % formatter(x) vals = self.values is_float = lib.map_infer(vals, com.is_float) & notnull(vals) leading_space = is_float.any() fmt_values = [] for i, v in enumerate(vals): if not is_float[i] and leading_space: fmt_values.append(' %s' % _format(v)) elif is_float[i]: fmt_values.append(float_format(v)) else: fmt_values.append(' %s' % _format(v)) return fmt_values