Exemple #1
0
 def testNoIndex(self):
     df = DataFrame([], ["x", "y"])
     x = [1, 2, 3]
     y = [4, 5, 6]
     df.setColumn("x", x)
     df.setColumn("y", y)
     with self.assertRaises(ValueError):
         df.toDict()
     pd_df = df.toPandas()
     self.assertEqual(list(pd_df["x"]), x)
     self.assertEqual(list(pd_df["y"]), y)
Exemple #2
0
 def testDict(self):
     dic = {"aa": "bb", "c": "a"}
     self.assertEqual(dic, DataFrame.fromDict(dic).toDict())
     dic = {1: 2}
     self.assertEqual(dic, DataFrame.fromDict(dic).toDict())
     dic = {1: 2, 3: 4}
     self.assertEqual(dic, DataFrame.fromDict(dic).toDict())
     dic = {2.0: ("a", "b"), 3: ("1", "2")}
     self.assertEqual(dic, DataFrame.fromDict(dic).toDict())
     dic = {(2.0, "c"): ("a", "b"), (3, "a"): ("1", "2")}
     self.assertEqual(dic, DataFrame.fromDict(dic).toDict())
     df = DataFrame("x", "y")
     dic = {1: 12, 2: 23}
     df.setValues(dic)
     self.assertEqual(dic, df.toDict())
     df = DataFrame("x", ["y", "z"])
     dic = {1: (12, 2), 2: (23, -1)}
     df.setValues(dic)
     self.assertEqual(dic, df.toDict())
     df = DataFrame("x", ["y", "z"])
     df.setValues({1: [1, 2]})
     self.assertEqual({1: (1, 2)}, df.toDict())