classification
Title: decimal.py: quantize(): excess digits with watchexp=0
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, mark.dickinson, python-dev, rhettinger, skrah
Priority: normal Keywords: patch

Created on 2010-12-08 13:56 by skrah, last changed 2014-04-30 17:16 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
issue10650.diff skrah, 2012-08-25 15:15 review
Messages (10)
msg123603 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-12-08 13:56
I'm not sure if this is a documentation issue or a bug. If watchexp=0,
quantize() also allows any number of digits:


>>> x = Decimal("6885998238912213556789006667970467609814")
>>> y = Decimal("1e2")
>>> x.quantize(y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/decimal.py", line 2488, in quantize
    'quantize result has too many digits for current context')
  File "/usr/local/lib/python3.2/decimal.py", line 3925, in _raise_error
    raise error(explanation)
decimal.InvalidOperation: quantize result has too many digits for current context
>>> 
>>> x.quantize(y, watchexp=0)
Decimal('6.8859982389122135567890066679704676098E+39')
msg123607 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-12-08 14:36
NaNs, however, are decapitated:

>>> x = Decimal("NaN5357671565858315212612021522416387828577")
>>> y = 0
>>> x.quantize(y, watchexp=0)
Decimal('NaN8315212612021522416387828577')
msg164429 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-06-30 21:56
Ping. We have to decide if we need watchexp in _decimal. I've left it
out so far since all I can gather from the docs is that it somehow
behaves like _rescale.

Can we deprecate it and replace it by a proper rescale?
msg164430 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-06-30 22:03
I'd be happy to see watchexp deprecated.  It feels like a leftover implementation artefact;  its behaviour isn't properly defined anywhere, and as far as I can tell it has only a single testcase.
msg164439 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012-07-01 00:40
Does anyone know why watchexp was put there in the first place?

http://speleotrove.com/decimal/daops.html#refquant

If no motivation for this can be found, I agree with Mark that it should be deprecated and removed.
msg164467 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-07-01 09:42
watchexp was available in rescale() from the beginning ...

http://svn.python.org/view/sandbox/trunk/decimal/Decimal.py?revision=40721&view=markup


... and rescale() was renamed to quantize() in

http://svn.python.org/view/sandbox/trunk/decimal/Decimal.py?revision=40909&view=markup


rescale() was once part of the specification, but had identical semantics to
quantize(), which is not specified to allow unlimited rescaling.


I suppose the original rescale() in the sandbox had watchexp for convenience,
in order to avoid two separate functions.

watchexp made it into quantize(), probably because people thought there is
a need for unlimited rescaling. This may be true, but I'd really prefer to
expose rescale() as the unlimited version then.


While it's unusual to just drop an API without deprecation, I think it's OK
in this instance: Virtually all decimal code I saw needs to be cleaned up
anyway because it uses tons of underscore methods from decimal.py.


The only thing that worries me is that there might be code which *really*
needs unlimited rescaling. Such code could of course also use a temporary
context.


So I propose this: Deprecate watchexp and leave it in the Python version for
one release. The C version won't have watchexp from the start. After all,
PEP-399 allows accelerator modules to implement a subset of the functionality
of the Python version -- sometimes PEPs are a wonderful thing :).
msg169141 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-08-25 15:14
Here's a patch deprecating watchexp.
msg169448 - (view) Author: Roundup Robot (python-dev) Date: 2012-08-30 10:39
New changeset 7db16ff9f5fd by Stefan Krah in branch 'default':
Closes #10650: Deprecate the watchexp parameter of Decimal.quantize().
http://hg.python.org/cpython/rev/7db16ff9f5fd
msg170085 - (view) Author: Roundup Robot (python-dev) Date: 2012-09-09 09:18
New changeset e4ca4edee8bd by Stefan Krah in branch 'default':
Closes #10650: Deprecate the watchexp parameter of Decimal.quantize().
http://hg.python.org/cpython/rev/e4ca4edee8bd
msg217631 - (view) Author: Roundup Robot (python-dev) Date: 2014-04-30 17:16
New changeset c2f827af02a2 by Stefan Krah in branch 'default':
Issue #10650: Remove the non-standard 'watchexp' parameter from the
http://hg.python.org/cpython/rev/c2f827af02a2
History
Date User Action Args
2014-04-30 17:16:20python-devsetmessages: + msg217631
2012-09-09 09:18:53python-devsetmessages: + msg170085
2012-08-30 10:39:41python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg169448

resolution: fixed
stage: resolved
2012-08-25 15:15:34skrahsetfiles: + issue10650.diff
keywords: + patch
2012-08-25 15:14:56skrahsetmessages: + msg169141
2012-07-01 09:42:29skrahsetmessages: + msg164467
2012-07-01 00:40:48rhettingersetmessages: + msg164439
2012-06-30 22:03:04mark.dickinsonsetmessages: + msg164430
2012-06-30 21:56:08skrahsetnosy: + georg.brandl
messages: + msg164429
2010-12-08 14:36:13skrahsetmessages: + msg123607
2010-12-08 13:56:10skrahcreate