Skip to content

BUG: display.precision option seems off-by-one #10451

Closed
@rosnfeld

Description

@rosnfeld

I may very well be wrong on this, given how common an option it seems, but I am surprised that the "display.precision" option seems to limit the digits after the decimal to one less than specified.

In [1]: x = pd.Series(np.random.randn(5))

In [2]: x
Out[2]: 
0   -0.163960
1    1.016273
2    0.861317
3   -0.521916
4   -0.069322
dtype: float64

In [3]: pd.set_option('display.precision', 3)

In [4]: x
Out[4]: 
0   -0.16
1    1.02
2    0.86
3   -0.52
4   -0.07
dtype: float64

I can't see where in the code this is happening. At first glance, this looks like what the code is doing:

In [13]: fmt_str = '%% .%dg' % 3

In [14]: fmt_str % x[0]
Out[14]: '-0.164'

but clearly something else is happening.

numpy's precision seems fine/meets my expectations:

In [10]: np.set_printoptions(precision=3)

In [11]: np.random.randn(5)
Out[11]: array([ 0.569, -2.638,  0.707,  0.675,  1.191])

So is this a bug? (if so it's been around for a long time) Or are my expectations off?

This was tested on current pandas master (as of writing) with numpy 1.9.2 and python 3.4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions