示例#1
0
 def test_dict(self):
     dic = {"aa": "bb", "c": "a"}
     self.assertEqual(dic, DataFrame.from_dict(dic).to_dict())
     dic = {1: 2}
     self.assertEqual(dic, DataFrame.from_dict(dic).to_dict())
     dic = {1: 2, 3: 4}
     self.assertEqual(dic, DataFrame.from_dict(dic).to_dict())
     dic = {2.0: ("a", "b"), 3: ("1", "2")}
     self.assertEqual(dic, DataFrame.from_dict(dic).to_dict())
     dic = {(2.0, "c"): ("a", "b"), (3, "a"): ("1", "2")}
     self.assertEqual(dic, DataFrame.from_dict(dic).to_dict())
     df = DataFrame("x", "y")
     dic = {1: 12, 2: 23}
     df.set_values(dic)
     self.assertEqual(dic, df.to_dict())
     df = DataFrame("x", ["y", "z"])
     dic = {1: (12, 2), 2: (23, -1)}
     df.set_values(dic)
     self.assertEqual(dic, df.to_dict())
     df = DataFrame("x", ["y", "z"])
     df.set_values({1: [1, 2]})
     self.assertEqual({1: (1, 2)}, df.to_dict())
示例#2
0
 def test_iter(self):
     df = DataFrame("x", "y")
     dic = {1: 12, 2: 23}
     df.set_values(dic)
     for row in df:
         self.assertTrue(tuple(row) in [(1, 12), (2, 23)])