Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add truedivide and floordivide to MV2 #192

Merged
merged 5 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/MV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions Lib/avariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion Lib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<CDMS " + filerep[loc:-1] + ", status: %s>" % self._status_
Expand Down
4 changes: 1 addition & 3 deletions Lib/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__

Expand Down
2 changes: 1 addition & 1 deletion Lib/hgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Lib/tvariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down