[Scipy-svn] r3329 - trunk/scipy/sandbox/maskedarray
scipy-svn at scipy.org
scipy-svn at scipy.org
Tue Sep 18 23:32:33 EDT 2007
Author: pierregm
Date: 2007-09-18 22:32:25 -0500 (Tue, 18 Sep 2007)
New Revision: 3329
Modified:
trunk/scipy/sandbox/maskedarray/mrecords.py
trunk/scipy/sandbox/maskedarray/testutils.py
Log:
testutils : introduced assert_equal_records
mrecords : MaskedRecords.__str__ : better support of record printing
Modified: trunk/scipy/sandbox/maskedarray/mrecords.py
===================================================================
--- trunk/scipy/sandbox/maskedarray/mrecords.py 2007-09-19 01:01:15 UTC (rev 3328)
+++ trunk/scipy/sandbox/maskedarray/mrecords.py 2007-09-19 03:32:25 UTC (rev 3329)
@@ -330,9 +330,9 @@
for s in zip(*[getattr(self,f) for f in self.dtype.names])]
return "[%s]" % ", ".join(mstr)
else:
- mstr = numeric.asarray(self._data.item(), dtype=object_)
- mstr[list(self._fieldmask)] = masked_print_option
- return str(mstr)
+ mstr = ["%s" % ",".join([str(i) for i in s])
+ for s in zip([getattr(self,f) for f in self.dtype.names])]
+ return "(%s)" % ", ".join(mstr)
def __repr__(self):
"""x.__repr__() <==> repr(x)
@@ -709,14 +709,14 @@
mrecfr = fromrecords(nrec.tolist(), names=nrec.dtype.names)
assert_equal(mrecfr.a, mrec.a)
assert_equal(mrecfr.dtype, mrec.dtype)
- if 1:
+ if 0:
assert_equal(mrec.a, MA.array(d,mask=m))
assert_equal(mrec.b, MA.array(d[::-1],mask=m[::-1]))
assert((mrec._fieldmask == N.core.records.fromarrays([m, m[::-1]])).all())
assert_equal(mrec._mask, N.r_[[m,m[::-1]]].all(0))
assert_equal(mrec.a[1], mrec[1].a)
- if 1:
+ if 0:
x = [(1.,10.,'a'),(2.,20,'b'),(3.14,30,'c'),(5.55,40,'d')]
desc = [('ffloat', N.float_), ('fint', N.int_), ('fstr', 'S10')]
mr = MaskedRecords(x,dtype=desc)
Modified: trunk/scipy/sandbox/maskedarray/testutils.py
===================================================================
--- trunk/scipy/sandbox/maskedarray/testutils.py 2007-09-19 01:01:15 UTC (rev 3328)
+++ trunk/scipy/sandbox/maskedarray/testutils.py 2007-09-19 03:32:25 UTC (rev 3329)
@@ -47,6 +47,14 @@
assert_equal(actual[k], desired[k], 'item=%r\n%s' % (k,err_msg))
return
+def assert_equal_records(a,b):
+ """Asserts that two records are equal. Pretty crude for now."""
+ assert_equal(a.dtype, b.dtype)
+ for f in a.dtype.names:
+ (af, bf) = (getattr(a,f), getattr(b,f))
+ if not (af is masked) and not (bf is masked):
+ assert_equal(getattr(a,f), getattr(b,f))
+ return
def assert_equal(actual,desired,err_msg=''):
"""Asserts that two items are equal.
More information about the Scipy-svn
mailing list