Example #1
0
 def test_alias_with_delete_computed_attributes(self):
     # Make an alias for an expression, then delete all computed attributes, then use the same alias
     # for a different expression.  This tests that the dictionary of aliases that have been defined
     # is cleared when you delete attributes.
     expr1 = "x = 2*sqrt(var1+var2)"
     storage = StorageFactory().get_storage('dict_storage')
     storage.write_table(table_name='dataset',
                         table_data={
                             "var1": array([4, -8, 0.5, 1]),
                             "var2": array([3, 3, 7, 7]),
                             "id": array([1, 2, 3, 4])
                         })
     dataset = Dataset(in_storage=storage,
                       in_table_name='dataset',
                       id_name="id",
                       dataset_name="mydataset")
     result = dataset.compute_variables([expr1])
     should_be = array([5.29150262, 0.0, 5.47722558, 5.65685425])
     self.assert_(ma.allclose(result, should_be, rtol=1e-6),
                  "Error in test_alias_with_delete_computed_attributes")
     dataset.delete_computed_attributes()
     # now alias x to a different expression
     expr2 = "x = var1+10"
     # check that the new var has x as an alias
     result2 = dataset.compute_variables([expr2])
     should_be2 = array([14, 2, 10.5, 11])
     self.assert_(ma.allclose(result2, should_be2, rtol=1e-6),
                  "Error in test_alias_with_delete_computed_attributes")
Example #2
0
 def test_alias_with_delete_computed_attributes(self):
     # Make an alias for an expression, then delete all computed attributes, then use the same alias
     # for a different expression.  This tests that the dictionary of aliases that have been defined
     # is cleared when you delete attributes.
     expr1 = "x = 2*sqrt(var1+var2)"
     storage = StorageFactory().get_storage('dict_storage')
     storage.write_table(
         table_name='dataset',
         table_data={"var1": array([4,-8,0.5,1]), "var2": array([3,3,7,7]), "id": array([1,2,3,4])}
         )
     dataset = Dataset(in_storage=storage, in_table_name='dataset', id_name="id", dataset_name="mydataset")
     result = dataset.compute_variables([expr1])
     should_be = array([ 5.29150262, 0.0,  5.47722558,  5.65685425])
     self.assert_(ma.allclose(result, should_be, rtol=1e-6), "Error in test_alias_with_delete_computed_attributes")
     dataset.delete_computed_attributes()
     # now alias x to a different expression
     expr2 = "x = var1+10"
     # check that the new var has x as an alias
     result2 = dataset.compute_variables([expr2])
     should_be2 = array([14, 2, 10.5, 11])
     self.assert_(ma.allclose(result2, should_be2, rtol=1e-6), "Error in test_alias_with_delete_computed_attributes")