diff options
author | seberg <sebastian@sipsolutions.net> | 2014-08-16 10:22:50 +0200 |
---|---|---|
committer | seberg <sebastian@sipsolutions.net> | 2014-08-16 10:22:50 +0200 |
commit | 412591201ab4e743a3710c476510e5dbbd4be93a (patch) | |
tree | 938d16dd7e38fbe573432304f5927ce95de5c41f /numpy/lib | |
parent | 50a1dfa08698aa3406085944d5007d99388c8a06 (diff) | |
parent | 9c7689794cf59fc0065da8bba1d97002c7be14e3 (diff) | |
download | numpy-412591201ab4e743a3710c476510e5dbbd4be93a.tar.gz |
Merge pull request #4968 from WarrenWeckesser/bug-genfromtxt
BUG: io: genfromtxt did not handle filling_values=0 correctly. Closes gh-2317.
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/npyio.py | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 0e49dd31c..21d98efe7 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -1518,7 +1518,9 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, # Process the filling_values ............................... # Rename the input for convenience - user_filling_values = filling_values or [] + user_filling_values = filling_values + if user_filling_values is None: + user_filling_values = [] # Define the default filling_values = [None] * nbcols # We have a dictionary : update each entry individually diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 03e238261..40a229d14 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -1300,6 +1300,16 @@ M 33 21.99 ctrl = np.array([(0, 3), (4, -999)], dtype=[(_, int) for _ in "ac"]) assert_equal(test, ctrl) + data2 = "1,2,*,4\n5,*,7,8\n" + test = np.genfromtxt(TextIO(data2), delimiter=',', dtype=int, + missing_values="*", filling_values=0) + ctrl = np.array([[1, 2, 0, 4], [5, 0, 7, 8]]) + assert_equal(test, ctrl) + test = np.genfromtxt(TextIO(data2), delimiter=',', dtype=int, + missing_values="*", filling_values=-1) + ctrl = np.array([[1, 2, -1, 4], [5, -1, 7, 8]]) + assert_equal(test, ctrl) + def test_withmissing_float(self): data = TextIO('A,B\n0,1.5\n2,-999.00') test = np.mafromtxt(data, dtype=None, delimiter=',', |