def test_API(self): fo = open(TESTFN, 'wb') fo.write(''' "A", "B", "C" 1, 2, 3.2 7, 4, 1.87''') fo.close() s = Sniff(TESTFN) self.assertEqual(s.comments(), '#') self.assertEqual(s.delimiter(), ',') self.assertEqual(s.skiprows(), 1) self.assertEqual(s.dtype(), { 'names': ('A', 'B', 'C'), 'formats': (float, float, float) }) x = s.loadtxt() y = array([(1.0, 2.0, 3.20), (7.0, 4.0, 1.87)], dtype=[('A', float), ('B', float), ('C', float)]) self.assertNamedClose(x, y) y = loadtxt(TESTFN, **s.kwds()) self.assertNamedClose(x, y) y = loadtxt_unknown(TESTFN) self.assertNamedClose(x, y) d = array2dict(y) self.assertEqual(type(d), type({})) self.assertAllClose(x['A'], [1, 7]) self.assertAllClose(x['B'], [2, 4]) self.assertAllClose(x['C'], [3.2, 1.87])
def test_API(self): fo = tempfile.mktemp() with open(fo, "w") as f: f.write( """ "A", "B", "C" 1, 2, 3.2 7, 4, 1.87""" ) s = Sniff(fo) self.assertEqual(s.comments(), "#") self.assertEqual(s.delimiter(), ",") self.assertEqual(s.skiprows(), 1) self.assertEqual(s.dtype(), {"names": ("A", "B", "C"), "formats": (float, float, float)}) x = s.loadtxt() y = array([(1.0, 2.0, 3.20), (7.0, 4.0, 1.87)], dtype=[("A", float), ("B", float), ("C", float)]) self.assertNamedClose(x, y) y = loadtxt(fo, **s.kwds()) self.assertNamedClose(x, y) y = loadtxt_unknown(fo) self.assertNamedClose(x, y) d = array2dict(y) self.assertEqual(type(d), type({})) self.assertAllClose(x["A"], [1, 7]) self.assertAllClose(x["B"], [2, 4]) self.assertAllClose(x["C"], [3.2, 1.87])
def test_API(self): fo = tempfile.mktemp() with open(fo, 'w', encoding="utf-8") as f: f.write(''' "A", "B", "C" 1, 2, 3.2 7, 4, 1.87''') s = Sniff(fo) self.assertEqual(s.comments(), '#') self.assertEqual(s.delimiter(), ',') self.assertEqual(s.skiprows(), 1) self.assertEqual(s.dtype(), {'names': ('A', 'B', 'C'), 'formats': (float, float, float)}) x = s.loadtxt() y = array([(1.0, 2.0, 3.20), (7.0, 4.0, 1.87)], dtype=[('A', float), ('B', float), ('C', float)]) self.assertNamedClose(x, y) with open(fo, 'r', encoding="utf-8") as fh: y = loadtxt(fh, **s.kwds()) self.assertNamedClose(x, y) y = loadtxt_unknown(fo) self.assertNamedClose(x, y) d = array2dict(y) self.assertEqual(type(d), type({})) self.assertAllClose(x['A'], [1, 7]) self.assertAllClose(x['B'], [2, 4]) self.assertAllClose(x['C'], [3.2, 1.87])
def test_API(self): fo = open(TESTFN, 'wb') fo.write(''' "A", "B", "C" 1, 2, 3.2 7, 4, 1.87''') fo.close() s = Sniff(TESTFN) self.assertEqual(s.comments(), '#') self.assertEqual(s.delimiter(), ',') self.assertEqual(s.skiprows(), 1) self.assertEqual(s.dtype(), {'names': ('A', 'B', 'C'), 'formats': (float, float, float)}) x = s.loadtxt() y = array([(1.0, 2.0, 3.20), (7.0, 4.0, 1.87)], dtype=[('A', float), ('B', float), ('C', float)]) self.assertNamedClose(x, y) y = loadtxt(TESTFN, **s.kwds()) self.assertNamedClose(x, y) y = loadtxt_unknown(TESTFN) self.assertNamedClose(x, y) d = array2dict(y) self.assertEqual(type(d), type({})) self.assertAllClose(x['A'], [1, 7]) self.assertAllClose(x['B'], [2, 4]) self.assertAllClose(x['C'], [3.2, 1.87])