Пример #1
0
    def test_repr_unsortable(self):
        # columns are not sortable
        import warnings
        warn_filters = warnings.filters
        warnings.filterwarnings('ignore',
                                category=FutureWarning,
                                module=".*format")

        unsortable = DataFrame(
            {
                'foo': [1] * 50,
                datetime.today(): [1] * 50,
                'bar': ['bar'] * 50,
                datetime.today() + timedelta(1): ['bar'] * 50
            },
            index=np.arange(50))
        repr(unsortable)

        fmt.set_option('display.precision', 3, 'display.column_space', 10)
        repr(self.frame)

        fmt.set_option('display.max_rows', 10, 'display.max_columns', 2)
        repr(self.frame)

        fmt.set_option('display.max_rows', 1000, 'display.max_columns', 1000)
        repr(self.frame)

        tm.reset_display_options()

        warnings.filters = warn_filters
Пример #2
0
    def test_eng_float_formatter(self):
        df = DataFrame({'A': [1.41, 141., 14100, 1410000.]})

        fmt.set_eng_float_format()
        result = df.to_string()
        expected = ('             A\n'
                    '0    1.410E+00\n'
                    '1  141.000E+00\n'
                    '2   14.100E+03\n'
                    '3    1.410E+06')
        assert result == expected

        fmt.set_eng_float_format(use_eng_prefix=True)
        result = df.to_string()
        expected = ('         A\n'
                    '0    1.410\n'
                    '1  141.000\n'
                    '2  14.100k\n'
                    '3   1.410M')
        assert result == expected

        fmt.set_eng_float_format(accuracy=0)
        result = df.to_string()
        expected = ('         A\n'
                    '0    1E+00\n'
                    '1  141E+00\n'
                    '2   14E+03\n'
                    '3    1E+06')
        assert result == expected

        tm.reset_display_options()
Пример #3
0
    def test_eng_float_formatter(self):
        df = DataFrame({"A": [1.41, 141.0, 14100, 1410000.0]})

        fmt.set_eng_float_format()
        result = df.to_string()
        expected = (
            "             A\n"
            "0    1.410E+00\n"
            "1  141.000E+00\n"
            "2   14.100E+03\n"
            "3    1.410E+06"
        )
        assert result == expected

        fmt.set_eng_float_format(use_eng_prefix=True)
        result = df.to_string()
        expected = (
            "         A\n" "0    1.410\n" "1  141.000\n" "2  14.100k\n" "3   1.410M"
        )
        assert result == expected

        fmt.set_eng_float_format(accuracy=0)
        result = df.to_string()
        expected = (
            "         A\n" "0    1E+00\n" "1  141E+00\n" "2   14E+03\n" "3    1E+06"
        )
        assert result == expected

        tm.reset_display_options()
Пример #4
0
    def test_repr_unsortable(self):
        # columns are not sortable
        import warnings
        warn_filters = warnings.filters
        warnings.filterwarnings('ignore',
                                category=FutureWarning,
                                module=".*format")

        unsortable = DataFrame({'foo': [1] * 50,
                                datetime.today(): [1] * 50,
                                'bar': ['bar'] * 50,
                                datetime.today() + timedelta(1): ['bar'] * 50},
                               index=np.arange(50))
        repr(unsortable)

        fmt.set_option('display.precision', 3, 'display.column_space', 10)
        repr(self.frame)

        fmt.set_option('display.max_rows', 10, 'display.max_columns', 2)
        repr(self.frame)

        fmt.set_option('display.max_rows', 1000, 'display.max_columns', 1000)
        repr(self.frame)

        tm.reset_display_options()

        warnings.filters = warn_filters
Пример #5
0
    def test_eng_float_formatter(self):
        df = DataFrame({'A': [1.41, 141., 14100, 1410000.]})

        fmt.set_eng_float_format()
        result = df.to_string()
        expected = ('             A\n'
                    '0    1.410E+00\n'
                    '1  141.000E+00\n'
                    '2   14.100E+03\n'
                    '3    1.410E+06')
        assert result == expected

        fmt.set_eng_float_format(use_eng_prefix=True)
        result = df.to_string()
        expected = ('         A\n'
                    '0    1.410\n'
                    '1  141.000\n'
                    '2  14.100k\n'
                    '3   1.410M')
        assert result == expected

        fmt.set_eng_float_format(accuracy=0)
        result = df.to_string()
        expected = ('         A\n'
                    '0    1E+00\n'
                    '1  141E+00\n'
                    '2   14E+03\n'
                    '3    1E+06')
        assert result == expected

        tm.reset_display_options()
Пример #6
0
    def test_repr_unsortable(self):
        # columns are not sortable
        import warnings

        warn_filters = warnings.filters
        warnings.filterwarnings("ignore",
                                category=FutureWarning,
                                module=".*format")

        unsortable = DataFrame(
            {
                "foo": [1] * 50,
                datetime.today(): [1] * 50,
                "bar": ["bar"] * 50,
                datetime.today() + timedelta(1): ["bar"] * 50,
            },
            index=np.arange(50),
        )
        repr(unsortable)

        fmt.set_option("display.precision", 3, "display.column_space", 10)
        repr(self.frame)

        fmt.set_option("display.max_rows", 10, "display.max_columns", 2)
        repr(self.frame)

        fmt.set_option("display.max_rows", 1000, "display.max_columns", 1000)
        repr(self.frame)

        tm.reset_display_options()

        warnings.filters = warn_filters
Пример #7
0
def test_format_sparse_config(idx):
    warn_filters = warnings.filters
    warnings.filterwarnings('ignore', category=FutureWarning,
                            module=".*format")
    # GH1538
    pd.set_option('display.multi_sparse', False)

    result = idx.format()
    assert result[1] == 'foo  two'

    tm.reset_display_options()

    warnings.filters = warn_filters
Пример #8
0
def test_format_sparse_config(idx):
    warn_filters = warnings.filters
    warnings.filterwarnings('ignore', category=FutureWarning,
                            module=".*format")
    # GH1538
    pd.set_option('display.multi_sparse', False)

    result = idx.format()
    assert result[1] == 'foo  two'

    tm.reset_display_options()

    warnings.filters = warn_filters
Пример #9
0
    def test_nan(self):
        # Issue #11981

        formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
        result = formatter(np.nan)
        assert result == 'NaN'

        df = pd.DataFrame({'a': [1.5, 10.3, 20.5],
                           'b': [50.3, 60.67, 70.12],
                           'c': [100.2, 101.33, 120.33]})
        pt = df.pivot_table(values='a', index='b', columns='c')
        fmt.set_eng_float_format(accuracy=1)
        result = pt.to_string()
        assert 'NaN' in result
        tm.reset_display_options()
Пример #10
0
    def test_nan(self):
        # Issue #11981

        formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
        result = formatter(np.nan)
        assert result == u('NaN')

        df = pd.DataFrame({'a': [1.5, 10.3, 20.5],
                           'b': [50.3, 60.67, 70.12],
                           'c': [100.2, 101.33, 120.33]})
        pt = df.pivot_table(values='a', index='b', columns='c')
        fmt.set_eng_float_format(accuracy=1)
        result = pt.to_string()
        assert 'NaN' in result
        tm.reset_display_options()
Пример #11
0
    def test_nan(self):
        # Issue #11981

        formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
        result = formatter(np.nan)
        assert result == "NaN"

        df = pd.DataFrame({
            "a": [1.5, 10.3, 20.5],
            "b": [50.3, 60.67, 70.12],
            "c": [100.2, 101.33, 120.33],
        })
        pt = df.pivot_table(values="a", index="b", columns="c")
        fmt.set_eng_float_format(accuracy=1)
        result = pt.to_string()
        assert "NaN" in result
        tm.reset_display_options()