def test_nullables(self): schema = test_schema + "nullables" pdf = PanDatFactory(table_with_stuffs=[["field one"], ["field two"]]) pdf.set_data_type("table_with_stuffs", "field one") pdf.set_data_type("table_with_stuffs", "field two", number_allowed=False, strings_allowed='*', nullable=True) tdf = TicDatFactory.create_from_full_schema( pdf.schema(include_ancillary_info=True)) tic_dat = tdf.TicDat( table_with_stuffs=[[101, "022"], [202, None], [303, "111"]]) dat = tdf.copy_to_pandas(tic_dat, drop_pk_columns=False) self.assertFalse(tdf.find_data_type_failures(tic_dat)) self.assertFalse(pdf.find_data_type_failures(dat)) pdf.pgsql.write_schema(self.engine, schema) pdf.pgsql.write_data(dat, self.engine, schema) dat_1 = pdf.pgsql.create_pan_dat(self.engine, schema) self.assertTrue( pdf._same_data(dat, dat_1, nans_are_same_for_data_rows=True)) tic_dat_1 = tdf.pgsql.create_tic_dat(self.engine, schema) self.assertTrue( tdf._same_data(tic_dat, tic_dat_1, nans_are_same_for_data_rows=True))
def testIssue45(self): schema = test_schema + "issue45" pdf = PanDatFactory(data=[["a"], ["b"]]) pdf.set_data_type("data", "b", number_allowed=False, strings_allowed='*') tdf = TicDatFactory.create_from_full_schema( pdf.schema(include_ancillary_info=True)) tic_dat = tdf.TicDat(data=[[2, "1"], [4, "3"], [44, "022"]]) dat = tdf.copy_to_pandas(tic_dat, drop_pk_columns=False) self.assertFalse(tdf.find_data_type_failures(tic_dat)) self.assertFalse(pdf.find_data_type_failures(dat)) pdf.pgsql.write_schema(self.engine, schema, forced_field_types={("data", "a"): "integer"}) pdf.pgsql.write_data(dat, self.engine, schema) def two_checks(): dat_1 = pdf.pgsql.create_pan_dat(self.engine, schema) self.assertTrue(pdf._same_data(dat, dat_1)) tic_dat_1 = tdf.pgsql.create_tic_dat(self.engine, schema) self.assertTrue(tdf._same_data(tic_dat, tic_dat_1)) two_checks() tdf.pgsql.write_data(tic_dat, self.engine, schema) two_checks()
def test_parameters_pd(self): schema = test_schema + "_parameters_pd" pdf = PanDatFactory(parameters=[["Key"], ["Value"]]) pdf.add_parameter("Something", 100) pdf.add_parameter("Different", 'boo', strings_allowed='*', number_allowed=False) dat = TicDatFactory(**pdf.schema()).TicDat( parameters=[["Something", float("inf")], ["Different", "inf"]]) dat = TicDatFactory(**pdf.schema()).copy_to_pandas( dat, drop_pk_columns=False) pdf.pgsql.write_schema(self.engine, schema) pdf.pgsql.write_data(dat, self.engine, schema) dat_ = pdf.pgsql.create_pan_dat(self.engine, schema) self.assertTrue(pdf._same_data(dat, dat_))
var Buy {j in FOOD} >= 0; var Consume {i in CAT } >= n_min [i], <= n_max [i]; minimize Total_Cost: sum {j in FOOD} cost[j] * Buy[j]; subject to Diet {i in CAT}: Consume[i] = sum {j in FOOD} (amt[j,i] + other_amt[j,i]) * Buy[j]; """ _diet_input_pdf = PanDatFactory( categories=[["Name"], ["Min Nutrition", "Max Nutrition"]], foods=[["Name"], ["Cost"]], nutrition_quantities=[["Food", "Category"], ["Quantity", "Other Quantity"]]) _diet_pan_dat_from_dict = lambda pd_dict: _pan_dat_maker_from_dict( _diet_input_pdf.schema(), pd_dict) _diet_dat = _pan_dat_maker_from_dict( _diet_input_pdf.schema(), { 'categories': { u'calories': { 'Max Nutrition': 2200.0, 'Min Nutrition': 1800 }, u'fat': { 'Max Nutrition': 65.0, 'Min Nutrition': 0 }, u'protein': { 'Max Nutrition': float('inf'), 'Min Nutrition': 91 },