Hi Jan,
A Dimarts 22 Agost 2006 04:03, Jan Strube va escriure:
> Now:
> Please have a look at the attached file. running tableBug.py causes the
> following error on my machine:
> Traceback (most recent call last):
[snip...]
> Now the behavior of this is very strange:
> a) removing the pos= statements in X.py results in no crash
> b) baryon1 and baryon2 are of the same type, but baryon1/uid exists,
> while baryon2/uid does not.
> c) removing the two statements to access the ndim of the column (meaning
> just doing the filling) results in no crash. (At least here)
This is a bug. Find attached the cure. I'm attaching also new unit tests for
checking that the fix works ok in case you are interested in.
Thanks for reporting this!
--
>0,0< Francesc Altet http://www.carabos.com/
V V Cárabos Coop. V. Enjoy Data
"-"
Index: tables/IsDescription.py
===================================================================
--- tables/IsDescription.py (revision 1677)
+++ tables/IsDescription.py (working copy)
@@ -27,6 +27,7 @@
import warnings
import sys
import operator
+import copy
import numarray as NA
import numarray.records as records
@@ -1015,16 +1016,34 @@
elif (type(object) == type(IsDescription) and
issubclass(object, IsDescription)):
#print "Nested object (type I)-->", k
- descr = object()
- classdict[k] = Description(descr.columns, self._v_nestedlvl)
+ # Doing a deepcopy is very important when one has nested
+ # records in the form:
+ #
+ # class Nested(IsDescription):
+ # uid = IntCol()
+ #
+ # class B_Candidate(IsDescription):
+ # nested1 = Nested
+ # nested2 = Nested
+ #
+ # This makes that nested1 and nested2 point to the same
+ # 'columns' dictionary, so that successive accesses to
+ # the different columns are actually accessing to the
+ # very same object.
+ # F. Altet 2006-08-22
+ columns = copy.deepcopy(object().columns)
+ classdict[k] = Description(columns, self._v_nestedlvl)
elif (type(object.__class__) == type(IsDescription) and
issubclass(object.__class__, IsDescription)):
#print "Nested object (type II)-->", k
- descr = object.__class__()
- classdict[k] = Description(descr.columns, self._v_nestedlvl)
+ # Regarding the need of a deepcopy, see note above
+ columns = copy.deepcopy(object.columns)
+ classdict[k] = Description(columns, self._v_nestedlvl)
elif isinstance(object, dict):
#print "Nested object (type III)-->", k
- classdict[k] = Description(object, self._v_nestedlvl)
+ # Regarding the need of a deepcopy, see note above
+ columns = copy.deepcopy(object)
+ classdict[k] = Description(columns, self._v_nestedlvl)
# Check if we have any ._v_pos position attribute
for column in classdict.values():
Index: tables/tests/test_nestedtypes.py
===================================================================
--- tables/tests/test_nestedtypes.py (revision 1677)
+++ tables/tests/test_nestedtypes.py (working copy)
@@ -1016,7 +1016,162 @@
reopen = 1
+class Nested(t.IsDescription):
+ uid = t.IntCol(pos=1)
+ value = t.FloatCol(pos=2)
+class A_Candidate(t.IsDescription):
+ nested1 = Nested()
+ nested2 = Nested()
+
+class B_Candidate(t.IsDescription):
+ nested1 = Nested
+ nested2 = Nested
+
+class C_Candidate(t.IsDescription):
+ nested1 = Nested()
+ nested2 = Nested
+
+Dnested = {'uid': t.IntCol(pos=1),
+ 'value': t.FloatCol(pos=2),
+ }
+
+D_Candidate = {"nested1": Dnested,
+ "nested2": Dnested,
+ }
+
+E_Candidate = {"nested1": Nested,
+ "nested2": Dnested,
+ }
+
+F_Candidate = {"nested1": Nested(),
+ "nested2": Dnested,
+ }
+
+class SameNestedTestCase(common.TempFileMixin, common.PyTablesTestCase):
+ """Checking several nested columns declared in the same way."""
+
+ correct_names = ['', # The root of columns
+ 'nested1', 'nested1/uid', 'nested1/value',
+ 'nested2', 'nested2/uid', 'nested2/value']
+
+ def test01a(self):
+ """Checking same nested columns (instance flavor)."""
+
+ self._verboseHeader()
+ tbl = self.h5file.createTable(
+ '/', 'test', A_Candidate, title=self._getMethodName())
+
+ if self.reopen:
+ self._reopen()
+ tbl = self.h5file.root.test
+
+ names = [col._v_pathname for col in tbl.description._v_walk(type="All")]
+ if verbose:
+ print "Pathnames of columns:", names
+ print "Should look like:", self.correct_names
+ self.assert_(names == self.correct_names,
+ "Column nested names doesn't match.")
+
+ def test01b(self):
+ """Checking same nested columns (class flavor)."""
+
+ self._verboseHeader()
+ tbl = self.h5file.createTable(
+ '/', 'test', B_Candidate, title=self._getMethodName())
+
+ if self.reopen:
+ self._reopen()
+ tbl = self.h5file.root.test
+
+ names = [col._v_pathname for col in tbl.description._v_walk(type="All")]
+ if verbose:
+ print "Pathnames of columns:", names
+ print "Should look like:", self.correct_names
+ self.assert_(names == self.correct_names,
+ "Column nested names doesn't match.")
+
+ def test01c(self):
+ """Checking same nested columns (mixed instance/class flavor)."""
+
+ self._verboseHeader()
+ tbl = self.h5file.createTable(
+ '/', 'test', C_Candidate, title=self._getMethodName())
+
+ if self.reopen:
+ self._reopen()
+ tbl = self.h5file.root.test
+
+ names = [col._v_pathname for col in tbl.description._v_walk(type="All")]
+ if verbose:
+ print "Pathnames of columns:", names
+ print "Should look like:", self.correct_names
+ self.assert_(names == self.correct_names,
+ "Column nested names doesn't match.")
+
+ def test01d(self):
+ """Checking same nested columns (dictionary flavor)."""
+
+ self._verboseHeader()
+ tbl = self.h5file.createTable(
+ '/', 'test', D_Candidate, title=self._getMethodName())
+
+ if self.reopen:
+ self._reopen()
+ tbl = self.h5file.root.test
+
+ names = [col._v_pathname for col in tbl.description._v_walk(type="All")]
+ if verbose:
+ print "Pathnames of columns:", names
+ print "Should look like:", self.correct_names
+ self.assert_(names == self.correct_names,
+ "Column nested names doesn't match.")
+
+ def test01e(self):
+ """Checking same nested columns (mixed dictionary/class flavor)."""
+
+ self._verboseHeader()
+ tbl = self.h5file.createTable(
+ '/', 'test', E_Candidate, title=self._getMethodName())
+
+ if self.reopen:
+ self._reopen()
+ tbl = self.h5file.root.test
+
+ names = [col._v_pathname for col in tbl.description._v_walk(type="All")]
+ if verbose:
+ print "Pathnames of columns:", names
+ print "Should look like:", self.correct_names
+ self.assert_(names == self.correct_names,
+ "Column nested names doesn't match.")
+
+ def test01f(self):
+ """Checking same nested columns (mixed dictionary/instance flavor)."""
+
+ self._verboseHeader()
+ tbl = self.h5file.createTable(
+ '/', 'test', F_Candidate, title=self._getMethodName())
+
+ if self.reopen:
+ self._reopen()
+ tbl = self.h5file.root.test
+
+ names = [col._v_pathname for col in tbl.description._v_walk(type="All")]
+ if verbose:
+ print "Pathnames of columns:", names
+ print "Should look like:", self.correct_names
+ self.assert_(names == self.correct_names,
+ "Column nested names doesn't match.")
+
+
+class SameNestedNoReopen(SameNestedTestCase):
+ reopen = 0
+
+class SameNestedReopen(SameNestedTestCase):
+ reopen = 1
+
+
+
#----------------------------------------------------------------------
def suite():
@@ -1037,6 +1192,8 @@
theSuite.addTest(unittest.makeSuite(ColsReopen))
theSuite.addTest(unittest.makeSuite(ReadNoReopen))
theSuite.addTest(unittest.makeSuite(ReadReopen))
+ theSuite.addTest(unittest.makeSuite(SameNestedNoReopen))
+ theSuite.addTest(unittest.makeSuite(SameNestedReopen))
return theSuite
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users