On Jan 5, 2008 3:34 PM, Mark Dickinson
On Jan 5, 2008 5:54 PM,
wrote: At first I didn't realize why I'd missed this feature. While the rounding *modes* are well documented, though, after 20 minutes of reading documentation I still haven't found a method or function that simply rounds a decimal to a given significant digit. Is there one, should there be one, or is the user simply meant to use Context.quantize with appropriate arguments?
quantize is about as close as it gets. Note that it's a Decimal method as well as a Context method, so you can invoke it directly on a given decimal:
Decimal("2.34567").quantize(Decimal("0.01")) Decimal("2.35")
I've also occasionally felt a need for a simple rounding function that isn't affected by context. Would others be interested in such a function being added to Decimal? I guess there are two possibly useful operations: (1) round to a particular decimal place ( e.g. nearest ten, nearest hundredth, ..) and (2) to round to a particular number of significant digits; in both cases, the user should be able to specify the desired rounding mode. And for each operation, it might also be useful to specify whether the result should be padded with zeros to the desired length or not. ( i.e. when rounding 3.399 to 3 significant places, should it produce 3.4 or 3.40?)
Any thoughts?
I think pep 3141's round(x, ndigits) does (1). The only thing it doesn't support yet is specifying the rounding mode. Perhaps the pep should say that round() passes any extra named arguments on to the __round__() method so that users can specify a rounding mode for types that support it? The Real interface doesn't say anything about significant digits, so Decimal can do whatever we want. My first guess would be that round should remove significant digits but not add them. (i.e. round("3.199", 2) == "3.20" but round("3", 1) == "3".) As you know, I'm working on a patch to implement 3141 for Decimal at http://bugs.python.org/issue1623, which I'll update as soon as this thread comes to a conclusion. Other people who are interested in getting this right should add themselves to its nosy list so they can object before I check something dumb in. :) I currently plan to keep __round__ in 2.6's Decimal with 3.0's behavior because it no longer affects the round() builtin in 2.6. Users who want it can call it directly … or we might provide, in 2.6, a module that provides 3.0 versions of the core library functions that change behavior so that they can get the new round() explicitly. -- Namasté, Jeffrey Yasskin
I think pep 3141's round(x, ndigits) does (1). The only thing it doesn't support yet is specifying the rounding mode. Perhaps the pep should say that round() passes any extra named arguments on to the __round__() method so that users can specify a rounding mode for types that support it?
That would clutter the interface. Just specify a universal rounding mode for __round__ and have Decimal's implementation of that method comply. If someone wants more control than that, they can manipulate the decimal object directly. Raymond
On Jan 5, 2008 7:11 PM, Raymond Hettinger
I think pep 3141's round(x, ndigits) does (1). The only thing it doesn't support yet is specifying the rounding mode. Perhaps the pep should say that round() passes any extra named arguments on to the __round__() method so that users can specify a rounding mode for types that support it?
That would clutter the interface. Just specify a universal rounding mode for __round__ and have Decimal's implementation of that method comply.
Yeah, thinking about this more, a .round() method on Context objects seems like a better way to handle the part of Mark's request that the round builtin doesn't cover. Of course, there may be even better alternatives that I haven't thought of. I'll post a patch to http://bugs.python.org/issue1623 tomorrow so we have something concrete to talk about. -- Namasté, Jeffrey Yasskin
On Jan 6, 2008 1:21 AM, Jeffrey Yasskin
On Jan 5, 2008 7:11 PM, Raymond Hettinger
wrote: I think pep 3141's round(x, ndigits) does (1). The only thing it doesn't support yet is specifying the rounding mode. Perhaps the pep should say that round() passes any extra named arguments on to the __round__() method so that users can specify a rounding mode for types that support it?
That would clutter the interface. Just specify a universal rounding mode for __round__ and have Decimal's implementation of that method comply.
Yeah, thinking about this more, a .round() method on Context objects seems like a better way to handle the part of Mark's request that the round builtin doesn't cover. Of course, there may be even better alternatives that I haven't thought of. I'll post a patch to http://bugs.python.org/issue1623 tomorrow so we have something concrete to talk about.
The new patch is posted: http://bugs.python.org/file9080/decimal-3141.patch I'll implement Context.round() in a separate patch. Comment away. :) -- Namasté, Jeffrey Yasskin
FWIW, I don't think all of these patches are helpful. The implementations are so easy and the effects are so obvious, that it is
simply better to decide what to do first, then do it afterwards.
My own preference is to leave the decimal module alone (except for a __round__ method to be called by builtin.round). Adding more
methods to that module does not make it easier to use -- there are already a mind-numbing range of choices in the current, minimal
implementation of the spec. I would support having a separate module of convenience functions or a separate module that uses a
subset, but growth of the core module will only make it harder to use and more difficult to maintain. Another idea for
simplifcation is to write-up a good tutorial to the basics of using the module.
Please show restraint when proposing API changes to decimal -- I think it would be easy to do more harm than good.
Raymond
----- Original Message -----
From: "Jeffrey Yasskin"
On Jan 6, 2008 1:21 AM, Jeffrey Yasskin
wrote: On Jan 5, 2008 7:11 PM, Raymond Hettinger
wrote: I think pep 3141's round(x, ndigits) does (1). The only thing it doesn't support yet is specifying the rounding mode. Perhaps the pep should say that round() passes any extra named arguments on to the __round__() method so that users can specify a rounding mode for types that support it?
That would clutter the interface. Just specify a universal rounding mode for __round__ and have Decimal's implementation of that method comply.
Yeah, thinking about this more, a .round() method on Context objects seems like a better way to handle the part of Mark's request that the round builtin doesn't cover. Of course, there may be even better alternatives that I haven't thought of. I'll post a patch to http://bugs.python.org/issue1623 tomorrow so we have something concrete to talk about.
The new patch is posted: http://bugs.python.org/file9080/decimal-3141.patch I'll implement Context.round() in a separate patch. Comment away. :)
-- Namasté, Jeffrey Yasskin
On Jan 6, 2008 5:13 PM, Raymond Hettinger
FWIW, I don't think all of these patches are helpful. The implementations are so easy and the effects are so obvious, that it is simply better to decide what to do first, then do it afterwards.
My own preference is to leave the decimal module alone (except for a __round__ method to be called by builtin.round).
You must mean __trunc__ to support builtin.trunc(), since builtin.round no longer calls __round__ in 2.6. The other 3 methods specified by PEP 3141 aren't strictly necessary for 2.6, but they will be needed for 3.0. I'd rather not make the two versions of Decimal gratuitously different, so this patch puts them in the 2.6 version too. That's basically all of the changes in this patch, so I'm not sure exactly what you're objecting to. Could you be more precise? -- Namasté, Jeffrey Yasskin
[Jeffrey Yasskin]
The other 3 methods specified by PEP 3141 aren't strictly necessary for 2.6, but they will be needed for 3.0. I'd rather not make the two versions of Decimal gratuitously different, so this patch puts them in the 2.6 version too.
If I understand you correctly, then the patch backports magic methods that do not have corresponding invocation methods in Py2.6. So, they are basically useless. If that's true, then the patch is clutter -- it makes 2.6 less desirable. It is not obvious to me how this will help someone transition to Py3.0. I'm curious to hear how Guido makes the call on this. Also, the goal of keeping versions identical across 2.6 and 3.0 is at odds with previous discussions where I believe we said that that is *not* the goal and will likely not even be possible in many cases. Besides, if the invocation of the magic methods is different in 3.0, how are you going to keep the test suite code the same across versions? There should probably be a PEP sets clearer guidelines about what should be backported from Py3.0. Perhaps something like this: * If there is a new feature that can be implemented in both and will make both more attractive, then it should be in both. * If something is going away or changing in 3.0, then the 2.6 conversion tool mode should warn about it if possible. * If neither of the above apply, then leave 2.6 alone.
I'm not sure exactly what you're objecting to. Could you be more precise?
You note said: "I'll implement Context.round() in a separate patch. Comment away." Unless I misread what you're trying to do, that is a gratuitous API build-out (whether talking about Py2.6 or Py3.0) which adds a second-way-to-do-it to a module that already has a huge number of methods. Our goal is to keep that module as a minimal implementation of the spec. Fattening the API will make the module harder to use, not simpler. Raymond
On Jan 6, 2008 7:40 PM, Raymond Hettinger
[Jeffrey Yasskin]
The other 3 methods specified by PEP 3141 aren't strictly necessary for 2.6, but they will be needed for 3.0. I'd rather not make the two versions of Decimal gratuitously different, so this patch puts them in the 2.6 version too.
If I understand you correctly, then the patch backports magic methods that do not have corresponding invocation methods in Py2.6. So, they are basically useless. If that's true, then the patch is clutter -- it makes 2.6 less desirable. It is not obvious to me how this will help someone transition to Py3.0. I'm curious to hear how Guido makes the call on this.
Also, the goal of keeping versions identical across 2.6 and 3.0 is at odds with previous discussions where I believe we said that that is *not* the goal and will likely not even be possible in many cases. Besides, if the invocation of the magic methods is different in 3.0, how are you going to keep the test suite code the same across versions?
I tend to agree. 2.6 and 3.0 decimal already differ plenty.
There should probably be a PEP sets clearer guidelines about what should be backported from Py3.0.
Can you volunteer a draft? It could be PEP 3003. I'm probably too close to 3.0 to be able to objectively write this, which really represents end users' desire for stability in 2.6.
Perhaps something like this: * If there is a new feature that can be implemented in both and will make both more attractive, then it should be in both. * If something is going away or changing in 3.0, then the 2.6 conversion tool mode should warn about it if possible. * If neither of the above apply, then leave 2.6 alone.
I'm not sure exactly what you're objecting to. Could you be more precise?
You note said: "I'll implement Context.round() in a separate patch. Comment away."
Unless I misread what you're trying to do, that is a gratuitous API build-out (whether talking about Py2.6 or Py3.0) which adds a second-way-to-do-it to a module that already has a huge number of methods. Our goal is to keep that module as a minimal implementation of the spec. Fattening the API will make the module harder to use, not simpler.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
[Raymond]
There should probably be a PEP sets clearer guidelines about what should be backported from Py3.0.
Perhaps something like this: * If there is a new feature that can be implemented in both and will make both more attractive, then it should be in both. * If something is going away or changing in 3.0, then the 2.6 conversion tool mode should warn about it if possible. * If neither of the above apply, then leave 2.6 alone.
[Guido van Rossum]
Can you volunteer a draft? It could be PEP 3003. I'm probably too close to 3.0 to be able to objectively write this, which really represents end users' desire for stability in 2.6.
Yes. Will do. Raymond
On Jan 6, 2008 7:40 PM, Raymond Hettinger
[Jeffrey Yasskin]
The other 3 methods specified by PEP 3141 aren't strictly necessary for 2.6, but they will be needed for 3.0. I'd rather not make the two versions of Decimal gratuitously different, so this patch puts them in the 2.6 version too.
If I understand you correctly, then the patch backports magic methods that do not have corresponding invocation methods in Py2.6. So, they are basically useless. If that's true, then the patch is clutter -- it makes 2.6 less desirable. It is not obvious to me how this will help someone transition to Py3.0. I'm curious to hear how Guido makes the call on this.
Also, the goal of keeping versions identical across 2.6 and 3.0 is at odds with previous discussions where I believe we said that that is *not* the goal and will likely not even be possible in many cases. Besides, if the invocation of the magic methods is different in 3.0, how are you going to keep the test suite code the same across versions?
Given Guido's agreement, expect another version of this patch with only __trunc__.
There should probably be a PEP sets clearer guidelines about what should be backported from Py3.0. Perhaps something like this: * If there is a new feature that can be implemented in both and will make both more attractive, then it should be in both. * If something is going away or changing in 3.0, then the 2.6 conversion tool mode should warn about it if possible. * If neither of the above apply, then leave 2.6 alone.
I'm not sure exactly what you're objecting to. Could you be more precise?
You note said: "I'll implement Context.round() in a separate patch. Comment away."
Oh, sorry for not being clear then. I don't intend to write or discuss that separate patch until this one's approved and submitted. I think it's worth discussing eventually, but this change is more important. I mentioned this sentiment at http://bugs.python.org/msg59417 too, but clearly wasn't explicit enough in either case. -- Namasté, Jeffrey Yasskin
[Jeffrey Yasskin]
I'm not sure exactly what you're objecting to. Could you be more precise?
You note said: "I'll implement Context.round() in a separate patch. Comment away."
Oh, sorry for not being clear then. I don't intend to write or discuss that separate patch until this one's approved and submitted. I think it's worth discussing eventually, but this change is more important. I mentioned this sentiment at http://bugs.python.org/msg59417 too, but clearly wasn't explicit enough in either case.
It's hard to keep up with all of these patches and I'm growing concerned that some will sneak by. In the case of complex proposals, it is often helpful to have a patch that we can discuss concretely, but in the case of simple ones like this, they just clutter to patch tracker. There's no need to create the patch until the idea has been discussed. In the case of Context.round(), I've already advised against it. So, I'm not sure why you still intend write a separate patch and bring it back up for discussion. Ideally, it should die right now. The sentiment is unchanged -- please do not build-out the API for the decimal module. It is intended to be minimal and needs to stay that way. Further additions will only make it harder to use, harder to maintain, and will complicate efforts to rewrite the module in C. Raymond
On Jan 6, 2008 10:51 PM, Raymond Hettinger
[Jeffrey Yasskin]
I'm not sure exactly what you're objecting to. Could you be more precise?
You note said: "I'll implement Context.round() in a separate patch. Comment away."
Oh, sorry for not being clear then. I don't intend to write or discuss that separate patch until this one's approved and submitted. I think it's worth discussing eventually, but this change is more important. I mentioned this sentiment at http://bugs.python.org/msg59417 too, but clearly wasn't explicit enough in either case.
It's hard to keep up with all of these patches and I'm growing concerned that some will sneak by.
You're certainly right to be concerned. The most significant patch, the original backport of 3141, _did_ sneak through. The only email I've gotten about it has been in response to my question about a detail. I don't know how I could have made it more obvious though: nobody who suggested the backport (http://bugs.python.org/issue1623) seemed to think it would be contentious enough to suggest emailing this list first. Since then, I've tried to keep things transparent by suggesting that you add yourself to the nosy list of http://bugs.python.org/issue1623, which is where I'll post any patches before thinking about committing them.
In the case of complex proposals, it is often helpful to have a patch that we can discuss concretely, but in the case of simple ones like this, they just clutter to patch tracker. There's no need to create the patch until the idea has been discussed.
I always like to have a patch around because abstract discussions, even (especially?) on simple topics, have a tendency to run off into the weeds. A patch keeps things focused and moving forward.
In the case of Context.round(), I've already advised against it. So, I'm not sure why you still intend write a separate patch and bring it back up for discussion. Ideally, it should die right now.
You advised against it. Tim, Mark, and glyph advised for something like it. I think it's consistent with the fact that most operations on Decimal instances are mirrored on Context instances, and __round__ will be an operation on Decimal instances. That doesn't sound like enough agreement to simply drop the discussion.
The sentiment is unchanged -- please do not build-out the API for the decimal module. It is intended to be minimal and needs to stay that way. Further additions will only make it harder to use, harder to maintain, and will complicate efforts to rewrite the module in C.
I am not building out the decimal API. I am adding enough methods to
maintain the comment that "Decimal floating point objects share many
properties with the other builtin numeric types such as float and int.
All of the usual math operations and special methods apply." in both
2.6 and 3.0. After that's done, I am interested in talking about
adding one method that 3 people on this list have been interested in.
I understand that you need to be vigilant against extraneous methods,
but I'm really not just adding these on a whim.
On Jan 6, 2008 11:28 PM, Raymond Hettinger
[Jeffrey Yasskin]
Given Guido's agreement, expect another version of this patch with only __trunc__.
Why is __trunc__ being backported? Is a trunc() builtin being backported? What is the point for a synonym for int() and __int__ in Py2.6.
Unless I'm missing something, this doesn't improve Py2.6 in the least.
The trunc() builtin was backported in http://svn.python.org/view?rev=59671&view=rev and hasn't been rolled back. All of the reasons to include trunc() in 3.0 apply to 2.6. A couple that I like are: if trunc had been around in the beginning, __index__ would have been unnecessary; and the name says what it's doing, unlike int(). I don't know what Guido's reasoning was for accepting it into the PEP. -- Namasté, Jeffrey Yasskin
[Jeffrey Yasskin]
I always like to have a patch around because abstract discussions, even (especially?) on simple topics, have a tendency to run off into the weeds. A patch keeps things focused and moving forward.
Please recognize that our little system of patches and newsgroup discussions is easily overwhelmed by someone who is so prolific. Your work will not receive quality review and discussion if the volume blows beyond the bandwidth of the other participants.
The sentiment is unchanged -- please do not build-out the API for the decimal module. It is intended to be minimal and needs to stay that way. Further additions will only make it harder to use, harder to maintain, and will complicate efforts to rewrite the module in C.
I am not building out the decimal API. I am adding enough methods to maintain the comment that "Decimal floating point objects share many properties with the other builtin numeric types such as float and int. All of the usual math operations and special methods apply." in both 2.6 and 3.0. After that's done, I am interested in talking about adding one method that 3 people on this list have been interested in. I understand that you need to be vigilant against extraneous methods, but I'm really not just adding these on a whim.
Arghh! You seem hell-bent on jamming this in. Please leave the decimal module alone. It does *not* need both a round() method and a quantize() method. I read Glyph's note and agree that it wasn't obvious how to round with the existing API. That is a documentation problem, not a call to add duplicate methods. When one of the module authors asks you to refrain for expanding the API, please pay special attention. In this case, you are working directly against a core philosophy for the design and maintenance of the module. I admire your enthusiasm, but please hold it in check. Raymond
2008/1/7, Raymond Hettinger
Arghh! You seem hell-bent on jamming this in. Please leave the decimal module alone. It does *not* need both a round() method and a quantize() method.
Question. I'm so used to quantize that I don't care. And I'm, in general, -0 to adding new methods to Decimal and/or Context. But in Py3, when you make round(x), x.__round__ will be executed. Same with trunc, ceil and floor. And I think that Decimal should grow these __xxx__ methods. Having said that, the only thing that is not clear to me is if we should: - Diverge 2.6 and 3.0 decimal.py code - Add these __xxx__ to 2.6, and have still one code of decimal. Guido voted for this last one, in the issue 1623: """ If there aren't too many differences between the 2.6 and 3.0 version of decimal.py and your patch, do 2.6 first, then the next time we merge stuff into 3.0 from the trunk it'll be forward-ported automatically. """ But, in the light of this thread, and the new PEP that you will be writing, I think that now it's time to decide this. Regards, -- . Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://www.python.org/ar/
On Mon, Jan 07, 2008, Raymond Hettinger wrote:
[Jeffrey Yasskin]
I am not building out the decimal API. I am adding enough methods to maintain the comment that "Decimal floating point objects share many properties with the other builtin numeric types such as float and int. All of the usual math operations and special methods apply." in both 2.6 and 3.0. After that's done, I am interested in talking about adding one method that 3 people on this list have been interested in. I understand that you need to be vigilant against extraneous methods, but I'm really not just adding these on a whim.
Arghh! You seem hell-bent on jamming this in. Please leave the decimal module alone. It does *not* need both a round() method and a quantize() method.
I read Glyph's note and agree that it wasn't obvious how to round with the existing API. That is a documentation problem, not a call to add duplicate methods.
Excuse me. I have always thought that "quantize()" makes Decimal confusing in the context of the other mechanisms that Python makes available for other kinds of numbers. I have refrained from making an issue of it because I understand and (mostly) support the idea of keeping Decimal restricted to matching the decimal standard, but at this point, it seems that Tim Peters likes the idea, too. While I have a lot of respect for you, I think Uncle Timmy deserves some special respect, too.
When one of the module authors asks you to refrain for expanding the API, please pay special attention. In this case, you are working directly against a core philosophy for the design and maintenance of the module.
I'm not a current maintainer, but I was one of the instigators for the existence of Decimal. I understand that you're feeling frustrated about changes getting shoved in, but I don't think that discussion should be shut down because you have a particular point of view: the decimal module does not represent only your work. I suggest that the patches get dropped for the moment and the discussion rebooted. I haven't been following closely, but it seems that the main issue is that Python 3.0 is introducing a __round__() method. How do you think the decimal module should handle that? (Although I still like the idea of a .round() method for decimals, I think that round(Decimal()) is probably sufficient enough that I won't insist on it.) -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
[Aahz]
I have always thought that "quantize()" makes Decimal confusing in the context of the other mechanisms that Python makes available for other kinds of numbers.
No doubt, the spec made a number of choices that are obvious only if you work at IBM. And, there is no doubt, the module has a high level of complexity. Jeffrey is proposing to add a Context.round() method with the purpose of making the module easier to use. I contend that this is self-defeating on the face of it. Please count the number of existing Context methods ( http://docs.python.org/dev/library/decimal.html#context-objects ) and tell me that adding yet another method will reduce complexity or shorten the learning curve. In fact, it will just further confuse which method should be used. Also, I thought we were committed to a minimal implementation of the spec. One reason for this was that programs could be ported back and forth with other implementations of the spec. Another reason is that the core spec has extensive test cases while build-outs have none. And another reason is that we are trying to make life easier for someone (perhaps me) to rewrite the module in C. There is also the principle of having only one way to do it. However, we already have Decimal.quantize and Context.quantize and are about to introduce a number of magic methods callable from builtin functions. Do we really need even more ways to round? The rounding operation is so fundamental to the module that user must grapple with it at some point. Having multiple ways to do it will only make that task more difficult. I spent about a month of my life cleaning, documenting, and testing the decimal module to get it ready for prime time. I'm not at all pleased at the current proposal to add a duplicate method. If someone really cared about making the module easier to use, I would fully support efforts to write a tutorial on the fundamentals or an effort to write a client module implementing only a subset of the spec. Raymond
[Jeffrey Yasskin]
Given Guido's agreement, expect another version of this patch with only __trunc__.
Why is __trunc__ being backported? Is a trunc() builtin being backported? What is the point for a synonym for int() and __int__ in Py2.6. Unless I'm missing something, this doesn't improve Py2.6 in the least. Raymond
During the discussion about the new Rational implementation (http://bugs.python.org/issue1682), Guido and Raymond decided that Decimal should not implement the new Real ABC from PEP 3141. So I've closed http://bugs.python.org/issue1623 and won't be pursuing any of the extra rounding methods mentioned on this thread. -- Namasté, Jeffrey Yasskin
On Jan 12, 2008 5:09 PM, Jeffrey Yasskin
During the discussion about the new Rational implementation (http://bugs.python.org/issue1682), Guido and Raymond decided that Decimal should not implement the new Real ABC from PEP 3141. So I've closed http://bugs.python.org/issue1623 and won't be pursuing any of the extra rounding methods mentioned on this thread.
Well, I didn't really decide anything. I suggested that if the developers of Decimal preferred it, it might be better if Decimal did not implement the Real ABC, and Raymond said he indeed preferred it. Since this reduces the usefulness of numeric.Real, I'm somewhat disappointed in this outcome (as I imagine you are). However, Decimal has very little of my own sweat in it, and a lot of Raymond, Facundo (and others, including Mark), and the ABC thing is still somewhat experimental, so it wouldn't make sense for me to impose my ideas onto Decimal unilaterally, and I'm sure Raymond etc. have their reasons. -- --Guido van Rossum (home page: http://www.python.org/~guido/)
On Jan 12, 2008 8:21 PM, Guido van Rossum
On Jan 12, 2008 5:09 PM, Jeffrey Yasskin
wrote: During the discussion about the new Rational implementation (http://bugs.python.org/issue1682), Guido and Raymond decided that Decimal should not implement the new Real ABC from PEP 3141. So I've closed http://bugs.python.org/issue1623 and won't be pursuing any of the extra rounding methods mentioned on this thread.
Well, I didn't really decide anything. I suggested that if the developers of Decimal preferred it, it might be better if Decimal did not implement the Real ABC, and Raymond said he indeed preferred it.
Since this reduces the usefulness of numeric.Real, I'm somewhat disappointed in this outcome (as I imagine you are). However, Decimal has very little of my own sweat in it, and a lot of Raymond, Facundo (and others, including Mark), and the ABC thing is still somewhat experimental, so it wouldn't make sense for me to impose my ideas onto Decimal unilaterally, and I'm sure Raymond etc. have their reasons.
Sorry for misrepresenting you. I am a little disappointed, but if we're right that numbers.Real is a good idea, then users will ask for Decimal to implement it, and the Decimal developers can change their minds in 3.1. Since I'm not one of those users, I'm not the right person to argue for this anyway. :) -- Namasté, Jeffrey Yasskin
On Jan 13, 2008 6:12 PM, Jeffrey Yasskin
On Jan 12, 2008 8:21 PM, Guido van Rossum
wrote: On Jan 12, 2008 5:09 PM, Jeffrey Yasskin
wrote: During the discussion about the new Rational implementation (http://bugs.python.org/issue1682), Guido and Raymond decided that Decimal should not implement the new Real ABC from PEP 3141. So I've closed http://bugs.python.org/issue1623 and won't be pursuing any of the extra rounding methods mentioned on this thread.
Well, I didn't really decide anything. I suggested that if the developers of Decimal preferred it, it might be better if Decimal did not implement the Real ABC, and Raymond said he indeed preferred it.
Since this reduces the usefulness of numeric.Real, I'm somewhat disappointed in this outcome (as I imagine you are). However, Decimal has very little of my own sweat in it, and a lot of Raymond, Facundo (and others, including Mark), and the ABC thing is still somewhat experimental, so it wouldn't make sense for me to impose my ideas onto Decimal unilaterally, and I'm sure Raymond etc. have their reasons.
Sorry for misrepresenting you. I am a little disappointed, but if we're right that numbers.Real is a good idea, then users will ask for Decimal to implement it, and the Decimal developers can change their minds in 3.1. Since I'm not one of those users, I'm not the right person to argue for this anyway. :)
I haven't been watching the python-dev list for very long, so maybe this has already been discussed ad nauseam (in which case, sorry), but, from the devil's advocate-ish mathematics side of things, unless numbers.Decimal is planned to be implemented with infinite precision (which I doubt, but could not confirm with an admittedly small amount of research), shouldn't it implement numbers.Rational instead? Was this ever discussed, or was it just assumed that numbers.Real was the right decision? Cheers, Leif
On Jan 13, 2008 3:41 PM, Leif Walsh
I haven't been watching the python-dev list for very long, so maybe this has already been discussed ad nauseam (in which case, sorry), but, from the devil's advocate-ish mathematics side of things, unless numbers.Decimal is planned to be implemented with infinite precision (which I doubt, but could not confirm with an admittedly small amount of research), shouldn't it implement numbers.Rational instead? Was this ever discussed, or was it just assumed that numbers.Real was the right decision?
Guido mentioned the possibility briefly at http://mail.python.org/pipermail/python-3000/2007-April/007015.html ("One could argue that float and Decimal are <:Q, but I'm not sure if that makes things better pragmatically") but never really discussed as far as I can find (although I did think about it :). I prefer having float not implement Rational (Decimal's off the table) because developers usually think of them as approximations to arbitrary, possibly-irrational, real numbers, rather than as rational numbers with some odd constraints on their denominators. That is, to me, the ABCs a type implements are more about how developers should think about the type than the implementation of the type. [ A new thread is probably appropriate if anyone wants to discuss the philosophy, but I probably won't participate... ] -- Namasté, Jeffrey Yasskin
On Jan 13, 2008 7:26 PM, Jeffrey Yasskin
Guido mentioned the possibility briefly at http://mail.python.org/pipermail/python-3000/2007-April/007015.html ("One could argue that float and Decimal are <:Q, but I'm not sure if that makes things better pragmatically") but never really discussed as far as I can find (although I did think about it :).
Well, if nothing else, I'm certainly satisfied that my concerns about accuracy are being addressed. I will have to go read more of that discussion.
I prefer having float not implement Rational (Decimal's off the table) because developers usually think of them as approximations to arbitrary, possibly-irrational, real numbers, rather than as rational numbers with some odd constraints on their denominators. That is, to me, the ABCs a type implements are more about how developers should think about the type than the implementation of the type.
I see where you're coming from. My personal stance is that developers _shouldn't_ think that way, but I know that's an unpopular opinion, and isn't really worth discussion here.
[ A new thread is probably appropriate if anyone wants to discuss the philosophy, but I probably won't participate... ]
I don't feel any pressing need to continue this here and now. Thanks! -- Cheers, Leif
On 1/12/08, Guido van Rossum
On Jan 12, 2008 5:09 PM, Jeffrey Yasskin
wrote: During the discussion about the new Rational implementation (http://bugs.python.org/issue1682), Guido and Raymond decided that Decimal should not implement the new Real ABC from PEP 3141. So I've closed http://bugs.python.org/issue1623 and won't be pursuing any of the extra rounding methods mentioned on this thread.
Well, I didn't really decide anything. I suggested that if the developers of Decimal preferred it, it might be better if Decimal did not implement the Real ABC, and Raymond said he indeed preferred it.
I read his objections slightly differently. He is very clear that Decimal itself should be restricted to the standard, and therefore should not natively implement the extensions. But he also said that it might be reasonable for another package to subset or superset it in a friendlier way. numbers.py is a different module, which must be explicitly imported. If the objection is that >>> decimal.Decimal("43.2").imag would work (instead of throwing an exception) only when numbers.py has already been imported, then ... well, that confusion is inherent in the abstract classes. Or is the problem that it *still* wouldn't work, without help from the decimal module itself? In that case, 3rd party registration is fairly limited, and this might be a good candidate for trying to figure out ABCs and adapters *should* work together. -jJ
On Jan 14, 2008 5:48 AM, Jim Jewett
On 1/12/08, Guido van Rossum
wrote: On Jan 12, 2008 5:09 PM, Jeffrey Yasskin
wrote: During the discussion about the new Rational implementation (http://bugs.python.org/issue1682), Guido and Raymond decided that Decimal should not implement the new Real ABC from PEP 3141. So I've closed http://bugs.python.org/issue1623 and won't be pursuing any of the extra rounding methods mentioned on this thread.
Well, I didn't really decide anything. I suggested that if the developers of Decimal preferred it, it might be better if Decimal did not implement the Real ABC, and Raymond said he indeed preferred it.
I read his objections slightly differently.
He is very clear that Decimal itself should be restricted to the standard, and therefore should not natively implement the extensions.
Well, to me that sounds like idolizing the standard. The standard exists so as to ensure that decimal numbers have well-understood semantics that are implemented correctly. I don't think the standard was ever meant to exclude optimal interaction with the rest of a language. I'd like to see if ReXX implements numeric features over and above the standard.
But he also said that it might be reasonable for another package to subset or superset it in a friendlier way.
From a user's perspective, it might make more sense to move the strictly standard-conforming code into a module "decimal_standard" and make the friendlier-named "decimal" module be that friendly superset.
numbers.py is a different module, which must be explicitly imported.
If the objection is that
>>> decimal.Decimal("43.2").imag
would work (instead of throwing an exception) only when numbers.py has already been imported, then ... well, that confusion is inherent in the abstract classes.
Fortunately, the confusion is in your mind only, because that's not how ABCs work according to PEP 3119. While as a side effect of importing the numbers module, the Decimal class might become a virtual subclass of numbers.Real, that doesn't mean that implementation features are automatically added. The registration that might take place inside numbers.py *only* affects the outcome of isinstance() and issubclass() checks -- it doesn't magically add missing attributes or methods to the class.
Or is the problem that it *still* wouldn't work, without help from the decimal module itself?
Right.
In that case, 3rd party registration is fairly limited, and this might be a good candidate for trying to figure out ABCs and adapters *should* work together.
Of course 3rd party registration is limited -- there's no way that you could automatically define the right semantics, since the ABCs don't have a way to express semantics. PEP 3119 is meant as a *first step* towards adopting ABCs as a core feature. The changes added to collections.py and numbers.py are best considered as minimal examples. The main achievement of the PEP is probably the hooks that allow you to override isinstance() and issubclass(), plus the decision (which was discussed at length) to use ABCs (with virtual inheritance), not interfaces, to model similarities between class APIs. -- --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (7)
-
Aahz
-
Facundo Batista
-
Guido van Rossum
-
Jeffrey Yasskin
-
Jim Jewett
-
Leif Walsh
-
Raymond Hettinger