Ejemplo n.º 1
0
 def test_read_with_skipping_first_few_couple_lines(self):
     for skip in [0, 3, 13]:
         r1 = CSVReader(self.filename1, chunksize=30)
         out_with_skip = r1.get_output(skip=skip)[0]
         r2 = CSVReader(self.filename1, chunksize=30)
         out = r2.get_output()[0]
         np.testing.assert_almost_equal(out_with_skip, out[skip::],
                                        err_msg="The first %s rows were skipped, but that did not "
                                                "match the rows with skip=0 and sliced by [%s::]" % (skip, skip))
Ejemplo n.º 2
0
 def test_read_with_skipping_first_few_couple_lines_multiple_trajectoryfiles(self):
     for skip in [0, 3, 13]:
         r1 = CSVReader([self.filename1, self.filename2])
         out_with_skip = r1.get_output(skip=skip)
         r2 = CSVReader([self.filename1, self.filename2])
         out = r2.get_output()
         np.testing.assert_almost_equal(out_with_skip[0], out[0][skip::],
                                        err_msg="The first %s rows of the first file were skipped, but that did not "
                                                "match the rows with skip=0 and sliced by [%s::]" % (skip, skip))
         np.testing.assert_almost_equal(out_with_skip[1], out[1][skip::],
                                        err_msg="The first %s rows of the second file were skipped, but that did not"
                                                " match the rows with skip=0 and sliced by [%s::]" % (skip, skip))
Ejemplo n.º 3
0
 def test_read_with_skipping_first_few_couple_lines(self):
     for skip in [0, 3, 13]:
         # FIXME: opening the same file twice is not being liked by py27
         r1 = CSVReader(self.filename1, chunksize=30)
         out_with_skip = r1.get_output(skip=skip)[0]
         assert len(out_with_skip) == len(self.data[skip:])
         r2 = CSVReader(self.filename1, chunksize=30)
         self.maxDiff=None
         #self.assertDictEqual(r1.__dict__, r2.__dict__)
         out = r2.get_output()[0]
         np.testing.assert_almost_equal(out_with_skip, out[skip::],
                                        err_msg="The first %s rows were skipped, but that did not "
                                                "match the rows with skip=0 and sliced by [%s::]" % (skip, skip))
Ejemplo n.º 4
0
    def test_with_kwargs(self):
        args = {'header': 27}

        reader = CSVReader(self.filename1, **args)

        output = reader.get_output()
        np.testing.assert_almost_equal(output[0], self.data)
Ejemplo n.º 5
0
 def test_read_1file_oneline(self):
     tiny = np.array([1, 2, 3])
     with tempfile.NamedTemporaryFile(mode='wb', suffix='.dat', delete=False) as f:
         np.savetxt(f, tiny)
         f.close()
         reader = CSVReader(f.name, delimiters=" ")
         np.testing.assert_equal(reader.get_output()[0], np.atleast_2d(tiny).T)
Ejemplo n.º 6
0
    def test_with_kwargs(self):
        args = {'header': 27}

        reader = CSVReader(self.filename1, **args)

        output = reader.get_output()
        np.testing.assert_almost_equal(output[0], self.data)
Ejemplo n.º 7
0
    def test_with_stride(self):
        reader = CSVReader(self.filename1)

        for s in [2, 3, 7, 10]:
            output = reader.get_output(stride=s)[0]
            np.testing.assert_almost_equal(output,
                                           self.data[::s],
                                           err_msg="stride=%s" % s)
Ejemplo n.º 8
0
 def test_newline_at_eof_with_header(self):
     with tempfile.NamedTemporaryFile(mode='w', delete=False) as f:
         f.write("#x y z\n1 2 3\n4 5 6\n\n")
         f.close()
         desired = np.genfromtxt(f.name, dtype=np.float32).reshape(-1, 3)
         reader = CSVReader(f.name)
         result = reader.get_output()[0]
         np.testing.assert_allclose(result, desired)
Ejemplo n.º 9
0
    def test_read_1file_with_header(self):
        reader = CSVReader(self.file_with_header)
        self.assertEqual(reader.number_of_trajectories(), 1)
        self.assertEqual(reader.dimension(), self.nd)
        self.assertEqual(reader.n_frames_total(), self.nt)

        output = reader.get_output()

        np.testing.assert_almost_equal(output[0], self.data)
Ejemplo n.º 10
0
    def test_read_1file_with_header(self):
        reader = CSVReader(self.file_with_header)
        self.assertEqual(reader.number_of_trajectories(), 1)
        self.assertEqual(reader.dimension(), self.nd)
        self.assertEqual(reader.n_frames_total(), self.nt)

        output = reader.get_output()

        np.testing.assert_almost_equal(output[0], self.data)
Ejemplo n.º 11
0
 def test_holes_in_file(self):
     x = "1 2 3\n4 5 6\n7 8 9"
     desired = np.fromstring(x, sep=" ", dtype=np.float32).reshape(-1, 3)
     with tempfile.NamedTemporaryFile(mode='w', delete=False) as f:
         f.write(x)
         f.close()
         reader = CSVReader(f.name)
         result = reader.get_output()[0]
         np.testing.assert_allclose(result, desired)
Ejemplo n.º 12
0
 def test_newline_at_eof_carriage_return(self):
     x = "1 2 3\r\n4 5 6\r\n"
     desired = np.fromstring(x, sep=" ", dtype=np.float32).reshape(-1, 3)
     with tempfile.NamedTemporaryFile(mode='w', delete=False) as f:
         f.write(x)
         f.close()
         reader = CSVReader(f.name)
         result = reader.get_output()[0]
         np.testing.assert_allclose(result, desired)
Ejemplo n.º 13
0
    def test_with_stride(self):
        reader = CSVReader(self.filename1)

        for s in [2, 3, 7, 10]:
            output = reader.get_output(stride=s)[0]
            np.testing.assert_almost_equal(output, self.data[::s])