Example #1
0
    def test_wide_repr_multiindex_cols(self):
        with option_context('mode.sim_interactive', True):
            col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
            midx = pandas.MultiIndex.from_arrays(
                [np.array(col(10, 5)),
                 np.array(col(10, 5))])
            mcols = pandas.MultiIndex.from_arrays(
                [np.array(col(20, 3)),
                 np.array(col(20, 3))])
            df = DataFrame([col(20, 25) for _ in range(10)],
                           index=midx,
                           columns=mcols)
            df.index.names = ['Level 0', 'Level 1']
            set_option('display.expand_frame_repr', False)
            rep_str = repr(df)
            set_option('display.expand_frame_repr', True)
            wide_repr = repr(df)
            self.assert_(rep_str != wide_repr)

        with option_context('display.line_width', 120):
            wider_repr = repr(df)
            self.assert_(len(wider_repr) < len(wide_repr))
            self.assert_(len(wide_repr.splitlines()) == 14 * 10 - 1)

        reset_option('display.expand_frame_repr')
Example #2
0
    def test_wide_repr_wide_long_columns(self):
        set_option('test.interactive', True)

        df = DataFrame({'a': ['a'*30, 'b'*30], 'b': ['c'*70, 'd'*80]})

        result = repr(df)
        self.assertTrue('ccccc' in result)
        self.assertTrue('ddddd' in result)
        set_option('test.interactive', False)
Example #3
0
def barf(self, num_rows=5, max_col=None):
    """
        Keep on running into issues where in notebook, I want to just show everything.
    """
    from IPython.core.display import HTML
    import pandas.core.config as config
    config.set_option("display.max_columns", 1000)
    h = HTML(self.to_html())
    config.reset_option("display.max_columns")
    return h
Example #4
0
def barf(self, num_rows=5, max_col=None):
    """
        Keep on running into issues where in notebook, I want to just show everything.
    """
    from IPython.core.display import HTML
    import pandas.core.config as config
    config.set_option("display.max_columns", 1000)
    h = HTML(self.to_html())
    config.reset_option("display.max_columns")
    return h
Example #5
0
    def test_option_mpl_style(self):
        set_option('display.mpl_style', 'default')
        set_option('display.mpl_style', None)
        set_option('display.mpl_style', False)

        with tm.assertRaises(ValueError):
            set_option('display.mpl_style', 'default2')
Example #6
0
    def test_option_mpl_style(self):
        set_option("display.mpl_style", "default")
        set_option("display.mpl_style", None)
        set_option("display.mpl_style", False)

        with tm.assertRaises(ValueError):
            set_option("display.mpl_style", "default2")
Example #7
0
    def test_option_mpl_style(self):
        set_option('display.mpl_style', 'default')
        set_option('display.mpl_style', None)
        set_option('display.mpl_style', False)

        with tm.assertRaises(ValueError):
            set_option('display.mpl_style', 'default2')
Example #8
0
    def test_wide_repr_unicode(self):
        with option_context('mode.sim_interactive', True):
            col = lambda l, k: [tm.randu(k) for _ in xrange(l)]
            df = DataFrame([col(20, 25) for _ in range(10)])
            set_option('display.expand_frame_repr', False)
            rep_str = repr(df)
            set_option('display.expand_frame_repr', True)
            wide_repr = repr(df)
            self.assert_(rep_str != wide_repr)

            with option_context('display.line_width', 120):
                wider_repr = repr(df)
                self.assert_(len(wider_repr) < len(wide_repr))

        reset_option('display.expand_frame_repr')
Example #9
0
 def test_option_mpl_style(self):
     set_option("display.mpl_style", "default")
     set_option("display.mpl_style", None)
     set_option("display.mpl_style", False)
     try:
         set_option("display.mpl_style", "default2")
     except ValueError:
         pass
Example #10
0
 def test_option_mpl_style(self):
     set_option('display.mpl_style', 'default')
     set_option('display.mpl_style', None)
     set_option('display.mpl_style', False)
     try:
         set_option('display.mpl_style', 'default2')
     except ValueError:
         pass
Example #11
0
 def test_option_mpl_style(self):
     set_option('display.mpl_style', 'default')
     set_option('display.mpl_style', None)
     set_option('display.mpl_style', False)
     try:
         set_option('display.mpl_style', 'default2')
     except ValueError:
         pass
Example #12
0
    def test_wide_repr(self):
        with option_context("mode.sim_interactive", True):
            col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
            df = DataFrame([col(20, 25) for _ in range(10)])
            set_option("print.expand_frame_repr", False)
            rep_str = repr(df)
            set_option("print.expand_frame_repr", True)
            wide_repr = repr(df)
            self.assert_(rep_str != wide_repr)

            with option_context("print.line_width", 120):
                wider_repr = repr(df)
                self.assert_(len(wider_repr) < len(wide_repr))

        reset_option("print.expand_frame_repr")
Example #13
0
    def test_wide_repr_unicode(self):
        with option_context('mode.sim_interactive', True):
            col = lambda l, k: [tm.randu(k) for _ in xrange(l)]
            df = DataFrame([col(20, 25) for _ in range(10)])
            set_option('display.expand_frame_repr', False)
            rep_str = repr(df)
            set_option('display.expand_frame_repr', True)
            wide_repr = repr(df)
            self.assert_(rep_str != wide_repr)

            with option_context('display.line_width', 120):
                wider_repr = repr(df)
                self.assert_(len(wider_repr) < len(wide_repr))

        reset_option('display.expand_frame_repr')
Example #14
0
def set_eng_float_format(precision=None, accuracy=3, use_eng_prefix=False):
    """
    Alter default behavior on how float is formatted in DataFrame.
    Format float in engineering format. By accuracy, we mean the number of
    decimal digits after the floating point.

    See also EngFormatter.
    """
    if precision is not None:  # pragma: no cover
        import warnings
        warnings.warn("'precision' parameter in set_eng_float_format is "
                      "being renamed to 'accuracy'", FutureWarning)
        accuracy = precision

    set_option("print.float_format", EngFormatter(accuracy, use_eng_prefix))
    set_option("print.column_space", max(12, accuracy + 9))
Example #15
0
def set_eng_float_format(precision=None, accuracy=3, use_eng_prefix=False):
    """
    Alter default behavior on how float is formatted in DataFrame.
    Format float in engineering format. By accuracy, we mean the number of
    decimal digits after the floating point.

    See also EngFormatter.
    """
    if precision is not None:  # pragma: no cover
        import warnings
        warnings.warn(
            "'precision' parameter in set_eng_float_format is "
            "being renamed to 'accuracy'", FutureWarning)
        accuracy = precision

    set_option("display.float_format", EngFormatter(accuracy, use_eng_prefix))
    set_option("display.column_space", max(12, accuracy + 9))
Example #16
0
    def test_wide_repr_multiindex_cols(self):
        with option_context("mode.sim_interactive", True):
            col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
            midx = pandas.MultiIndex.from_arrays([np.array(col(10, 5)), np.array(col(10, 5))])
            mcols = pandas.MultiIndex.from_arrays([np.array(col(20, 3)), np.array(col(20, 3))])
            df = DataFrame([col(20, 25) for _ in range(10)], index=midx, columns=mcols)
            df.index.names = ["Level 0", "Level 1"]
            set_option("display.expand_frame_repr", False)
            rep_str = repr(df)
            set_option("display.expand_frame_repr", True)
            wide_repr = repr(df)
            self.assert_(rep_str != wide_repr)

        with option_context("display.line_width", 120):
            wider_repr = repr(df)
            self.assert_(len(wider_repr) < len(wide_repr))
            self.assert_(len(wide_repr.splitlines()) == 14 * 10 - 1)

        reset_option("display.expand_frame_repr")
Example #17
0
    def test_wide_repr_named(self):
        with option_context('mode.sim_interactive', True):
            col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
            df = DataFrame([col(20, 25) for _ in range(10)])
            df.index.name = 'DataFrame Index'
            set_option('display.expand_frame_repr', False)

            rep_str = repr(df)
            set_option('display.expand_frame_repr', True)
            wide_repr = repr(df)
            self.assert_(rep_str != wide_repr)

            with option_context('display.line_width', 120):
                wider_repr = repr(df)
                self.assert_(len(wider_repr) < len(wide_repr))

            for line in wide_repr.splitlines()[1::13]:
                self.assert_('DataFrame Index' in line)

        reset_option('display.expand_frame_repr')
Example #18
0
    def test_wide_repr_multiindex(self):
        with option_context("mode.sim_interactive", True):
            col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
            midx = pandas.MultiIndex.from_arrays([np.array(col(10, 5)), np.array(col(10, 5))])
            df = DataFrame([col(20, 25) for _ in range(10)], index=midx)
            df.index.names = ["Level 0", "Level 1"]
            set_option("print.expand_frame_repr", False)
            rep_str = repr(df)
            set_option("print.expand_frame_repr", True)
            wide_repr = repr(df)
            self.assert_(rep_str != wide_repr)

            with option_context("print.line_width", 120):
                wider_repr = repr(df)
                self.assert_(len(wider_repr) < len(wide_repr))

            for line in wide_repr.splitlines()[1::13]:
                self.assert_("Level 0 Level 1" in line)

        reset_option("print.expand_frame_repr")
Example #19
0
    def test_wide_repr_named(self):
        with option_context('mode.sim_interactive', True):
            col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
            df = DataFrame([col(20, 25) for _ in range(10)])
            df.index.name = 'DataFrame Index'
            set_option('display.expand_frame_repr', False)

            rep_str = repr(df)
            set_option('display.expand_frame_repr', True)
            wide_repr = repr(df)
            self.assert_(rep_str != wide_repr)

            with option_context('display.line_width', 120):
                wider_repr = repr(df)
                self.assert_(len(wider_repr) < len(wide_repr))

            for line in wide_repr.splitlines()[1::13]:
                self.assert_('DataFrame Index' in line)

        reset_option('display.expand_frame_repr')
Example #20
0
    def test_option_mpl_style(self):
        # just a sanity check
        try:
            import matplotlib
        except:
            raise nose.SkipTest

        set_option('display.mpl_style', 'default')
        set_option('display.mpl_style', None)
        set_option('display.mpl_style', False)
        try:
            set_option('display.mpl_style', 'default2')
        except ValueError:
            pass
Example #21
0
    def test_option_mpl_style(self):
        # just a sanity check
        try:
            import matplotlib
        except:
            raise nose.SkipTest

        set_option('display.mpl_style', 'default')
        set_option('display.mpl_style', None)
        set_option('display.mpl_style', False)
        try:
            set_option('display.mpl_style', 'default2')
        except ValueError:
            pass
Example #22
0
    def test_register_writer(self):
        # some awkward mocking to test out dispatch and such actually works
        called_save = []
        called_write_cells = []

        class DummyClass(ExcelWriter):
            called_save = False
            called_write_cells = False
            supported_extensions = ['test', 'xlsx', 'xls']
            engine = 'dummy'

            def save(self):
                called_save.append(True)

            def write_cells(self, *args, **kwargs):
                called_write_cells.append(True)

        def check_called(func):
            func()
            self.assert_(len(called_save) >= 1)
            self.assert_(len(called_write_cells) >= 1)
            del called_save[:]
            del called_write_cells[:]

        register_writer(DummyClass)
        writer = ExcelWriter('something.test')
        tm.assert_isinstance(writer, DummyClass)
        df = tm.makeCustomDataframe(1, 1)
        panel = tm.makePanel()
        func = lambda: df.to_excel('something.test')
        check_called(func)
        check_called(lambda: panel.to_excel('something.test'))
        from pandas import set_option, get_option
        val = get_option('io.excel.xlsx.writer')
        set_option('io.excel.xlsx.writer', 'dummy')
        check_called(lambda: df.to_excel('something.xlsx'))
        check_called(lambda: df.to_excel('something.xls', engine='dummy'))
        set_option('io.excel.xlsx.writer', val)
Example #23
0
    def test_register_writer(self):
        # some awkward mocking to test out dispatch and such actually works
        called_save = []
        called_write_cells = []

        class DummyClass(ExcelWriter):
            called_save = False
            called_write_cells = False
            supported_extensions = ['test', 'xlsx', 'xls']
            engine = 'dummy'

            def save(self):
                called_save.append(True)

            def write_cells(self, *args, **kwargs):
                called_write_cells.append(True)

        def check_called(func):
            func()
            self.assert_(len(called_save) >= 1)
            self.assert_(len(called_write_cells) >= 1)
            del called_save[:]
            del called_write_cells[:]

        register_writer(DummyClass)
        writer = ExcelWriter('something.test')
        tm.assert_isinstance(writer, DummyClass)
        df = tm.makeCustomDataframe(1, 1)
        panel = tm.makePanel()
        func = lambda: df.to_excel('something.test')
        check_called(func)
        check_called(lambda: panel.to_excel('something.test'))
        from pandas import set_option, get_option
        val = get_option('io.excel.xlsx.writer')
        set_option('io.excel.xlsx.writer', 'dummy')
        check_called(lambda: df.to_excel('something.xlsx'))
        check_called(lambda: df.to_excel('something.xls', engine='dummy'))
        set_option('io.excel.xlsx.writer', val)
Example #24
0
    def test_repr_truncation(self):
        max_len = 20
        set_option("print_config.max_colwidth", max_len)
        df = DataFrame(
            {"A": np.random.randn(10), "B": [tm.rands(np.random.randint(max_len - 1, max_len + 1)) for i in range(10)]}
        )
        r = repr(df)
        r = r[r.find("\n") + 1 :]
        for line, value in zip(r.split("\n"), df["B"]):
            if fmt._strlen(value) + 1 > max_len:
                self.assert_("..." in line)
            else:
                self.assert_("..." not in line)

        set_option("print_config.max_colwidth", 999999)
        self.assert_("..." not in repr(df))

        set_option("print_config.max_colwidth", max_len + 2)
        self.assert_("..." not in repr(df))
Example #25
0
    def test_repr_truncation(self):
        max_len = 20
        set_option("print_config.max_colwidth", max_len)
        df = DataFrame({'A': np.random.randn(10),
                 'B': [tm.rands(np.random.randint(max_len - 1,
                     max_len + 1)) for i in range(10)]})
        r = repr(df)
        r = r[r.find('\n') + 1:]
        for line, value in zip(r.split('\n'), df['B']):
            if fmt._strlen(value) + 1 > max_len:
                self.assert_('...' in line)
            else:
                self.assert_('...' not in line)

        set_option("print_config.max_colwidth", 999999)
        self.assert_('...' not in repr(df))

        set_option("print_config.max_colwidth", max_len + 2)
        self.assert_('...' not in repr(df))
Example #26
0
    def test_repr_truncation(self):
        max_len = 20
        set_option("print.max_colwidth", max_len)
        df = DataFrame({'A': np.random.randn(10),
                 'B': [tm.rands(np.random.randint(max_len - 1,
                     max_len + 1)) for i in range(10)]})
        r = repr(df)
        r = r[r.find('\n') + 1:]

        _strlen = fmt._strlen_func()

        for line, value in zip(r.split('\n'), df['B']):
            if _strlen(value) + 1 > max_len:
                self.assert_('...' in line)
            else:
                self.assert_('...' not in line)

        set_option("print.max_colwidth", 999999)
        self.assert_('...' not in repr(df))

        set_option("print.max_colwidth", max_len + 2)
        self.assert_('...' not in repr(df))
Example #27
0
    def test_wide_repr_unicode(self):
        set_option('test.interactive', True)
        col = lambda l, k: [tm.randu(k) for _ in xrange(l)]
        df = DataFrame([col(20, 25) for _ in range(10)])
        set_option('print.expand_frame_repr', False)
        rep_str = repr(df)
        set_option('print.expand_frame_repr', True)
        wide_repr = repr(df)
        self.assert_(rep_str != wide_repr)

        set_option('print.line_width', 120)
        wider_repr = repr(df)
        self.assert_(len(wider_repr) < len(wide_repr))

        reset_option('print.expand_frame_repr')
        set_option('test.interactive', False)
        set_option('print.line_width', 80)
Example #28
0
 def __init__(self):
     set_option('display.max_rows', None)
Example #29
0
def set_printoptions(precision=None,
                     column_space=None,
                     max_rows=None,
                     max_columns=None,
                     colheader_justify=None,
                     max_colwidth=None,
                     notebook_repr_html=None,
                     date_dayfirst=None,
                     date_yearfirst=None,
                     pprint_nest_depth=None,
                     multi_sparse=None,
                     encoding=None):
    """
    Alter default behavior of DataFrame.toString

    precision : int
        Floating point output precision (number of significant digits). This is
        only a suggestion
    column_space : int
        Default space for DataFrame columns, defaults to 12
    max_rows : int
    max_columns : int
        max_rows and max_columns are used in __repr__() methods to decide if
        to_string() or info() is used to render an object to a string.
        Either one, or both can be set to 0 (experimental). Pandas will figure
        out how big the terminal is and will not display more rows or/and
        columns that can fit on it.
    colheader_justify
    notebook_repr_html : boolean
        When True (default), IPython notebook will use html representation for
        pandas objects (if it is available).
    date_dayfirst : boolean
        When True, prints and parses dates with the day first, eg 20/01/2005
    date_yearfirst : boolean
        When True, prints and parses dates with the year first, eg 2005/01/20
    pprint_nest_depth : int
        Defaults to 3.
        Controls the number of nested levels to process when pretty-printing
        nested sequences.
    multi_sparse : boolean
        Default True, "sparsify" MultiIndex display (don't display repeated
        elements in outer levels within groups)
    """
    if precision is not None:
        set_option("print_config.precision", precision)
    if column_space is not None:
        set_option("print_config.column_space", column_space)
    if max_rows is not None:
        set_option("print_config.max_rows", max_rows)
    if max_colwidth is not None:
        set_option("print_config.max_colwidth", max_colwidth)
    if max_columns is not None:
        set_option("print_config.max_columns", max_columns)
    if colheader_justify is not None:
        set_option("print_config.colheader_justify", colheader_justify)
    if notebook_repr_html is not None:
        set_option("print_config.notebook_repr_html", notebook_repr_html)
    if date_dayfirst is not None:
        set_option("print_config.date_dayfirst", date_dayfirst)
    if date_yearfirst is not None:
        set_option("print_config.date_yearfirst", date_yearfirst)
    if pprint_nest_depth is not None:
        set_option("print_config.pprint_nest_depth", pprint_nest_depth)
    if multi_sparse is not None:
        set_option("print_config.multi_sparse", multi_sparse)
    if encoding is not None:
        set_option("print_config.encoding", encoding)
Example #30
0
 def tearDown(self):
     set_option(self.option_name, self.prev_engine)
Example #31
0
 def setUp(self):
     self.check_skip()
     super(ExcelWriterBase, self).setUp()
     self.option_name = 'io.excel.%s.writer' % self.ext.strip('.')
     self.prev_engine = get_option(self.option_name)
     set_option(self.option_name, self.engine_name)
Example #32
0
 def setUp(self):
     self.check_skip()
     super(ExcelWriterBase, self).setUp()
     self.option_name = 'io.excel.%s.writer' % self.ext.strip('.')
     self.prev_engine = get_option(self.option_name)
     set_option(self.option_name, self.engine_name)
Example #33
0
def set_printoptions(precision=None, column_space=None, max_rows=None,
                     max_columns=None, colheader_justify=None,
                     max_colwidth=None, notebook_repr_html=None,
                     date_dayfirst=None, date_yearfirst=None,
                     pprint_nest_depth=None,multi_sparse=None, encoding=None):
    """
    Alter default behavior of DataFrame.toString

    precision : int
        Floating point output precision (number of significant digits). This is
        only a suggestion
    column_space : int
        Default space for DataFrame columns, defaults to 12
    max_rows : int
    max_columns : int
        max_rows and max_columns are used in __repr__() methods to decide if
        to_string() or info() is used to render an object to a string.
        Either one, or both can be set to 0 (experimental). Pandas will figure
        out how big the terminal is and will not display more rows or/and
        columns that can fit on it.
    colheader_justify
    notebook_repr_html : boolean
        When True (default), IPython notebook will use html representation for
        pandas objects (if it is available).
    date_dayfirst : boolean
        When True, prints and parses dates with the day first, eg 20/01/2005
    date_yearfirst : boolean
        When True, prints and parses dates with the year first, eg 2005/01/20
    pprint_nest_depth : int
        Defaults to 3.
        Controls the number of nested levels to process when pretty-printing
        nested sequences.
    multi_sparse : boolean
        Default True, "sparsify" MultiIndex display (don't display repeated
        elements in outer levels within groups)
    """
    import warnings
    warnings.warn("set_printoptions is deprecated, use set_option instead",
                          FutureWarning)
    if precision is not None:
        set_option("print.precision", precision)
    if column_space is not None:
        set_option("print.column_space", column_space)
    if max_rows is not None:
        set_option("print.max_rows", max_rows)
    if max_colwidth is not None:
        set_option("print.max_colwidth", max_colwidth)
    if max_columns is not None:
        set_option("print.max_columns", max_columns)
    if colheader_justify is not None:
        set_option("print.colheader_justify", colheader_justify)
    if notebook_repr_html is not None:
        set_option("print.notebook_repr_html", notebook_repr_html)
    if date_dayfirst is not None:
        set_option("print.date_dayfirst", date_dayfirst)
    if date_yearfirst is not None:
        set_option("print.date_yearfirst", date_yearfirst)
    if pprint_nest_depth is not None:
        set_option("print.pprint_nest_depth", pprint_nest_depth)
    if multi_sparse is not None:
        set_option("print.multi_sparse", multi_sparse)
    if encoding is not None:
        set_option("print.encoding", encoding)
Example #34
0
 def tearDown(self):
     set_option(self.option_name, self.prev_engine)
Example #35
0
    def test_wide_repr_multiindex_cols(self):
        set_option('test.interactive', True)
        col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
        midx = pandas.MultiIndex.from_arrays([np.array(col(10, 5)),
                                              np.array(col(10, 5))])
        mcols = pandas.MultiIndex.from_arrays([np.array(col(20, 3)),
                                               np.array(col(20, 3))])
        df = DataFrame([col(20, 25) for _ in range(10)],
                       index=midx, columns=mcols)
        df.index.names = ['Level 0', 'Level 1']
        set_option('print.expand_frame_repr', False)
        rep_str = repr(df)
        set_option('print.expand_frame_repr', True)
        wide_repr = repr(df)
        self.assert_(rep_str != wide_repr)

        set_option('print.line_width', 120)
        wider_repr = repr(df)
        self.assert_(len(wider_repr) < len(wide_repr))

        self.assert_(len(wide_repr.splitlines()) == 14 * 10 - 1)

        reset_option('print.expand_frame_repr')
        set_option('test.interactive', False)
        set_option('print.line_width', 80)