From e1507752a26964464d08875352d1ee9b444b4c17 Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Wed, 9 Sep 2026 23:10:42 +0000 Subject: [PATCH] DOC: clarify timing precision accessors and repair doctest example Document that get_default_precision() is the read-only equivalent of float_precision() called with no argument, and note why both exist. Repair the float_precision() example so it passes under a strict doctest run: the print() line had no expected output. Also strip trailing whitespace and add the missing newline at end of file. Inspired by the docstring half of #914 by @lntutor. Closes out the documentation criteria of #889; the module was already fully covered by TestGlobalPrecision in quantecon/util/tests/test_timing.py. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016SV8c3M2nrjtkSSjQ6Ky2L --- quantecon/timings/__init__.py | 2 +- quantecon/timings/timings.py | 42 +++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/quantecon/timings/__init__.py b/quantecon/timings/__init__.py index 0eb0be3e3..d079560f8 100644 --- a/quantecon/timings/__init__.py +++ b/quantecon/timings/__init__.py @@ -4,4 +4,4 @@ from .timings import float_precision, get_default_precision -__all__ = ['float_precision', 'get_default_precision'] \ No newline at end of file +__all__ = ['float_precision', 'get_default_precision'] diff --git a/quantecon/timings/timings.py b/quantecon/timings/timings.py index edbd3c9a4..3a4fa5e6b 100644 --- a/quantecon/timings/timings.py +++ b/quantecon/timings/timings.py @@ -12,50 +12,58 @@ def float_precision(precision=None): """ Get or set the global float precision for timing outputs. - + Parameters ---------- precision : int, optional - Number of decimal places to display in timing outputs. + Number of decimal places to display in timing outputs. If None, returns the current precision setting. - + Returns ------- int Current precision value if precision=None, otherwise None. - + Examples -------- - Get current precision: + Get the current precision: + >>> import quantecon as qe - >>> current = qe.timings.float_precision() - >>> print(f"Current precision: {current}") - - Set new precision: + >>> qe.timings.float_precision() + 4 + + Set a new precision. All subsequent timing outputs use six decimal + places: + >>> qe.timings.float_precision(6) - >>> # All subsequent timing outputs will use 6 decimal places - - Reset to default: + + Reset to the default: + >>> qe.timings.float_precision(4) """ global _DEFAULT_FLOAT_PRECISION - + if precision is None: return _DEFAULT_FLOAT_PRECISION - + if not isinstance(precision, int) or precision < 0: raise ValueError("precision must be a non-negative integer") - + _DEFAULT_FLOAT_PRECISION = precision def get_default_precision(): """ Get the current default precision setting. - + + This is a read-only equivalent of calling :func:`float_precision` with + no argument; both return the same module-level value. It is the + accessor used internally by the timing utilities in + :mod:`quantecon.util.timing`, which only need to read the setting. + Returns ------- int Current default precision for timing outputs. """ - return _DEFAULT_FLOAT_PRECISION \ No newline at end of file + return _DEFAULT_FLOAT_PRECISION