From da9ff48c070e2e9e7eda2258217d6730558646c4 Mon Sep 17 00:00:00 2001
From: Marco Biasini <marco.biasini@unibas.ch>
Date: Fri, 31 Aug 2012 15:01:34 +0200
Subject: [PATCH] make sure to copy col_names and col_types when filtering a
 table

---
 modules/base/pymod/table.py      |  2 +-
 modules/base/tests/test_table.py | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/modules/base/pymod/table.py b/modules/base/pymod/table.py
index e8735c3e3..37c45feb9 100644
--- a/modules/base/pymod/table.py
+++ b/modules/base/pymod/table.py
@@ -756,7 +756,7 @@ Statistics for column %(col)s
     args are unary callables returning true if the row should be included in the
     result and false if not.
     """
-    filt_tab=Table(self.col_names, self.col_types)
+    filt_tab=Table(list(self.col_names), list(self.col_types))
     for row in self.rows:
       matches=True
       for func in args:
diff --git a/modules/base/tests/test_table.py b/modules/base/tests/test_table.py
index a2128d887..cd11bd729 100644
--- a/modules/base/tests/test_table.py
+++ b/modules/base/tests/test_table.py
@@ -315,6 +315,24 @@ class TestTable(unittest.TestCase):
     self.CompareColNames(tab, ['x'])
     self.CompareColTypes(tab, 'x', 'f')
     
+  def testTableFilterColNamesTypes(self):
+    """
+    make sure the col_names and col_types are copied. 
+    We don't want them to be referenced to the original table.
+    This leads to strange surprises.
+    """
+    t = Table(['a', 'b'], 'ii')
+    t.AddRow([1,2])
+    t.AddRow([2,3])
+    t.AddRow([2,3])
+    t.AddRow([3,3])
+    t.AddRow([4,3])
+    t.AddRow([5,3])
+    filt = t.Filter(a=2)
+    filt.AddCol('c', 'i')
+    self.assertEqual(len(t.col_names), 2)
+    self.assertEqual(len(t.col_types), 2)
+
   def testTableInitMultiColMultiValueNonEmpty(self):
     '''
     table with two column and four rows:
-- 
GitLab