Stephan:
> ...which is why I would suggest exposing it as a function parameter (rather than a global constant).
I'm
sorry I don't see what benefit in writing a new equality method on
every object in iris and helper functions to every numpy operation. A
global doesn't need to mean strictly 'constant'. This is why I'm trying
to separate the issue of end user utility to tackling the fundamental
issue at hand. For example let's take your context manager approach
(which I like by the way) and apply it to our 'global constant':
import config
from contextlib import contextmanager
@contextmanager
def set_global_tolerance(value):
orig = config.TOLERANCE
config.TOLERANCE = value
yield
config.TOLERANCE = orig
print config.TOLERANCE
with set_global_tolerance(1e-6):
print config.TOLERANCE
print config.TOLERANCE
Here would then be the output:
I'm
afraid this is simply not a luxury we have with Python. Being a
duck-typed language, our operations necessarily need to behave
reasonably when faced with integers or floats. I would certainly not
want to go down the route of unnecessary conditionals based on type. For example, a
coordinates points maybe integer or float.
> ...I am keen to limit impact to API users...
If your responding to my proposal, again I don't understand your point. My proposal would NOT change anything for the end-users directly.
This proposal is about providing the utilities for iris itself
to deal with floating point numbers correctly. That is, any '==',
'!=', '<=', '>=', '<', '>', 'np.equal', 'np.greater', ...
etc. calls on with relevant objects are replaced with calls to these
helper functions.
I want to stress that this is not
simply an enhancement but a package-wide solution to numerous 'bugs'
both discovered and undiscovered due to the handling of floats by iris.
I should also stress that iris handling of floats is shared amongst other users in science.
I still feel the problem I'm addressing and how I'm proposing to solve it is not understood.