From e011a61459caa7a781494d1ec2d35f372b4c6136 Mon Sep 17 00:00:00 2001 From: Denis Nadeau Date: Wed, 15 Nov 2017 21:57:12 -0800 Subject: [PATCH] add truedivide and floordivide to MV2 (#192) * add truedivide and floordivide to MV2 * fix iff->if in documentation * fix ci machines * flake8 --- Lib/MV2.py | 3 +++ Lib/avariable.py | 6 ++++++ Lib/dataset.py | 2 +- Lib/grid.py | 4 +--- Lib/hgrid.py | 2 +- Lib/tvariable.py | 2 ++ 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Lib/MV2.py b/Lib/MV2.py index 4da7e1d7..23d9dbc0 100644 --- a/Lib/MV2.py +++ b/Lib/MV2.py @@ -289,6 +289,8 @@ def compress(a, b): subtract = var_binary_operation(numpy.ma.subtract) multiply = var_binary_operation(numpy.ma.multiply) divide = var_binary_operation(numpy.ma.divide) +true_divide = var_binary_operation(numpy.ma.true_divide) +floor_divide = var_binary_operation(numpy.ma.floor_divide) equal = var_binary_operation(numpy.ma.equal) less_equal = var_binary_operation(numpy.ma.less_equal) greater_equal = var_binary_operation(numpy.ma.greater_equal) @@ -399,6 +401,7 @@ def set_print_limit(limit=numpy.inf): all = alltrue logical_not = var_unary_operation(numpy.ma.logical_not) divide.reduce = None +true_divide.reduce = None remainder = var_binary_operation(numpy.ma.remainder) remainder.reduce = None fmod = var_binary_operation(numpy.ma.fmod) diff --git a/Lib/avariable.py b/Lib/avariable.py index 5337d04d..822a12e5 100644 --- a/Lib/avariable.py +++ b/Lib/avariable.py @@ -1547,6 +1547,12 @@ def __mul__(self, other): __rmul__ = __mul__ + def __floordiv__(self, other): + return MV.floor_divide(self, other) + + def __truediv__(self, other): + return MV.true_divide(self, other) + def __div__(self, other): return MV.divide(self, other) diff --git a/Lib/dataset.py b/Lib/dataset.py index d13ecbd7..7303bb55 100644 --- a/Lib/dataset.py +++ b/Lib/dataset.py @@ -2196,7 +2196,7 @@ def getBoundsAxis(self, n, boundid=None): def __repr__(self): filerep = repr(self._file_) - loc = string.find(filerep, "file") + loc = filerep.find("file") if loc == -1: loc = 0 return "" % self._status_ diff --git a/Lib/grid.py b/Lib/grid.py index 2cc8b68b..5646859e 100644 --- a/Lib/grid.py +++ b/Lib/grid.py @@ -5,9 +5,7 @@ import re from .error import CDMSError import numpy # , PropertiedClasses, internattr -# import regrid2._regrid import copy -import string import sys from .cdmsobj import CdmsObj from .axis import TransientAxis, createAxis, createUniformLatitudeAxis @@ -195,7 +193,7 @@ def listall(self, all=None): return result def __str__(self): - return string.join(self.listall(), "\n") + "\n" + return "\n".join(self.listall()) __repr__ = __str__ diff --git a/Lib/hgrid.py b/Lib/hgrid.py index 7b5a504e..2e878559 100644 --- a/Lib/hgrid.py +++ b/Lib/hgrid.py @@ -662,7 +662,7 @@ def getAxisList(self): return (self._lataxis_.getAxis(0), self._lataxis_.getAxis(1)) def isClose(self, g): - """Return 1 iff g is a grid of the same type and shape. A real element-by-element + """Return 1 if g is a grid of the same type and shape. A real element-by-element comparison would be too expensive here.""" if g is None: return 0 diff --git a/Lib/tvariable.py b/Lib/tvariable.py index 0f4e5ada..d2decf16 100644 --- a/Lib/tvariable.py +++ b/Lib/tvariable.py @@ -137,6 +137,8 @@ def __copy__(self): __rsub__ = AbstractVariable.__rsub__ __isub__ = AbstractVariable.__isub__ __div__ = AbstractVariable.__div__ + __truediv__ = AbstractVariable.__truediv__ + __floordiv__ = AbstractVariable.__floordiv__ __rdiv__ = AbstractVariable.__rdiv__ __idiv__ = AbstractVariable.__idiv__ __pow__ = AbstractVariable.__pow__