[Python-Dev] Deprecating float.is_integer() (original) (raw)

Robert Smallshire rob at sixty-north.com
Wed Mar 21 12:52:20 EDT 2018


Here's an excerpted (and slightly simplified for consumption here) usage of float.is_integer() from the top of a function which does some convolution/filtering in a geophysics application. I've mostly seen it used in guard clauses in this way to reject either illegal numeric arguments directly, or particular combinations of arguments as in this case:

def filter_convolve(x, y, xf, yf, stride=1, padding=1): x_out = (x - xf + 2padding) / stride + 1 y_out = (y - yf + 2padding) / stride + 1

if not (x_out.is_integer() and y_out.is_integer()):
    raise ValueError("Invalid convolution filter_convolve({x},

{y}, {xf}, {yf}, {stride}, {padding})" .format(x=x, y=y, xf=xf, yf=yf, stride=stride, padding=padding)) x_out = int(x_out) y_out = int(y_out)

# ...

Of course, there are other ways to do this check, but the approach here is obvious and easy to comprehend. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180321/c299415c/attachment.html>



More information about the Python-Dev mailing list