Skip to content

Commit 9f84f64

Browse files
adamkleinwesm
authored andcommitted
ENH: #395 incorporate lodagro comments on disambiguating precision vs accuracy
Conflicts: pandas/core/common.py
1 parent 39ce914 commit 9f84f64

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

pandas/core/common.py

+28-15
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def set_printoptions(precision=None, column_space=None, max_rows=None,
372372
Alter default behavior of DataFrame.toString
373373
374374
precision : int
375-
Floating point output precision
375+
Floating point output precision (number of significant digits)
376376
column_space : int
377377
Default space for DataFrame columns, defaults to 12
378378
max_rows : int
@@ -427,22 +427,22 @@ class EngFormatter(object):
427427
24: "Y"
428428
}
429429

430-
def __init__(self, precision=None, use_eng_prefix=False):
431-
self.precision = precision
430+
def __init__(self, accuracy=None, use_eng_prefix=False):
431+
self.accuracy = accuracy
432432
self.use_eng_prefix = use_eng_prefix
433433

434434
def __call__(self, num):
435435
""" Formats a number in engineering notation, appending a letter
436436
representing the power of 1000 of the original number. Some examples:
437437
438-
>>> format_eng(0) # for self.precision = 0
438+
>>> format_eng(0) # for self.accuracy = 0
439439
'0'
440440
441-
>>> format_eng(1000000) # for self.precision = 1,
441+
>>> format_eng(1000000) # for self.accuracy = 1,
442442
# self.use_eng_prefix = True
443443
'1.0M'
444444
445-
>>> format_eng("-1e-6") # for self.precision = 2
445+
>>> format_eng("-1e-6") # for self.accuracy = 2
446446
# self.use_eng_prefix = False
447447
'-1.00E-06'
448448
@@ -480,27 +480,40 @@ def __call__(self, num):
480480

481481
mant = sign*dnum/(10**pow10)
482482

483-
if self.precision is None: # pragma: no cover
483+
if self.accuracy is None: # pragma: no cover
484484
format_str = u"%g%s"
485-
elif self.precision == 0:
485+
elif self.accuracy == 0:
486486
format_str = u"%i%s"
487-
elif self.precision > 0:
488-
format_str = (u"%% .%if%%s" % self.precision)
487+
elif self.accuracy > 0:
488+
format_str = (u"%% .%if%%s" % self.accuracy )
489489

490490
formatted = format_str % (mant, prefix)
491491

492492
return formatted #.strip()
493493

494-
def set_eng_float_format(precision=3, use_eng_prefix=False):
494+
def set_eng_float_format(precision=None, accuracy=3, use_eng_prefix=False):
495495
"""
496496
Alter default behavior on how float is formatted in DataFrame.
497-
Format float in engineering format.
497+
Format float in engineering format. By accuracy, we mean the number of
498+
decimal digits after the floating point.
498499
499500
See also EngFormatter.
500501
"""
501-
global GlobalPrintConfig
502-
GlobalPrintConfig.float_format = EngFormatter(precision, use_eng_prefix)
503-
GlobalPrintConfig.column_space = max(12, precision + 9)
502+
if precision is not None: # pragma: no cover
503+
import warnings
504+
warnings.warn("'precision' parameter in set_eng_float_format is "
505+
"being renamed to 'accuracy'" , FutureWarning)
506+
accuracy = precision
507+
508+
global _float_format, _column_space
509+
_float_format = EngFormatter(accuracy, use_eng_prefix)
510+
_column_space = max(12, accuracy + 9)
511+
512+
_float_format = None
513+
_column_space = 12
514+
_precision = 4
515+
_max_rows = 500
516+
_max_columns = 0
504517

505518
def _stringify(col):
506519
# unicode workaround

pandas/tests/test_frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ def test_eng_float_formatter(self):
16291629

16301630
repr(self.frame)
16311631

1632-
com.set_eng_float_format(precision=0)
1632+
com.set_eng_float_format(accuracy=0)
16331633

16341634
repr(self.frame)
16351635

0 commit comments

Comments
 (0)