From 0b0a389d1dfb6d76e053988d87f6434c81dd5ba5 Mon Sep 17 00:00:00 2001 From: dhuard Date: Wed, 9 Apr 2008 00:57:23 +0000 Subject: Added test for handling missing data using loadtxt. --- numpy/lib/tests/test_io.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'numpy/lib/tests/test_io.py') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index c219f6fcd..d0187fb58 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -72,6 +72,24 @@ class Testloadtxt(NumpyTestCase): x = np.loadtxt(c, dtype=int) a = np.array([1,2,3,4], int) assert_array_equal(x, a) + + c = StringIO.StringIO() + c.write('1,2,3,4\n') + c.seek(0) + x = np.loadtxt(c, dtype=int, delimiter=',') + a = np.array([1,2,3,4], int) + assert_array_equal(x, a) + + + def test_missing(self): + c = StringIO.StringIO() + c.write('1,2,3,,5\n') + c.seek(0) + x = np.loadtxt(c, dtype=int, delimiter=',', \ + converters={3:lambda s: int(s or -999)}) + a = np.array([1,2,3,-999,5], int) + assert_array_equal(x, a) + if __name__ == "__main__": NumpyTest().run() -- cgit v1.2.1