summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/release/1.9.0-notes.rst6
-rw-r--r--numpy/lib/npyio.py23
-rw-r--r--numpy/lib/tests/test_io.py8
3 files changed, 27 insertions, 10 deletions
diff --git a/doc/release/1.9.0-notes.rst b/doc/release/1.9.0-notes.rst
index b0adec0cf..ea2069c12 100644
--- a/doc/release/1.9.0-notes.rst
+++ b/doc/release/1.9.0-notes.rst
@@ -293,6 +293,12 @@ cases the arrays being iterated are as large as the iterator so that such
a problem cannot occur.
+`npyio.recfromcsv` keyword arguments change
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+`npyio.recfromcsv` no longer accepts the undocumented `update` keyword,
+which used to override the `dtype` keyword.
+
+
C-API
~~~~~
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 4268e6f06..f69ca0c73 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -1856,7 +1856,7 @@ def recfromtxt(fname, **kwargs):
array will be determined from the data.
"""
- kwargs.update(dtype=kwargs.get('dtype', None))
+ kwargs.setdefault("dtype", None)
usemask = kwargs.get('usemask', False)
output = genfromtxt(fname, **kwargs)
if usemask:
@@ -1883,17 +1883,20 @@ def recfromcsv(fname, **kwargs):
--------
numpy.genfromtxt : generic function to load ASCII data.
+ Notes
+ -----
+ By default, `dtype` is None, which means that the data-type of the output
+ array will be determined from the data.
+
"""
- case_sensitive = kwargs.get('case_sensitive', "lower") or "lower"
- names = kwargs.get('names', True)
- if names is None:
- names = True
- kwargs.update(dtype=kwargs.get('update', None),
- delimiter=kwargs.get('delimiter', ",") or ",",
- names=names,
- case_sensitive=case_sensitive)
- usemask = kwargs.get("usemask", False)
+ # Set default kwargs for genfromtxt as relevant to csv import.
+ kwargs.setdefault("case_sensitive", "lower")
+ kwargs.setdefault("names", True)
+ kwargs.setdefault("delimiter", ",")
+ kwargs.setdefault("dtype", None)
output = genfromtxt(fname, **kwargs)
+
+ usemask = kwargs.get("usemask", False)
if usemask:
from numpy.ma.mrecords import MaskedRecords
output = output.view(MaskedRecords)
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index a8b578097..418386e35 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1572,6 +1572,14 @@ M 33 21.99
dtype=[('a', np.int), ('b', np.int)])
self.assertTrue(isinstance(test, np.recarray))
assert_equal(test, control)
+ #
+ data = TextIO('A,B\n0,1\n2,3')
+ dtype = [('a', np.int), ('b', np.float)]
+ test = np.recfromcsv(data, missing_values='N/A', dtype=dtype)
+ control = np.array([(0, 1), (2, 3)],
+ dtype=dtype)
+ self.assertTrue(isinstance(test, np.recarray))
+ assert_equal(test, control)
def test_gft_using_filename(self):
# Test that we can load data from a filename as well as a file object