Repository: numpy/numpy

Issue:
npyio.py --> recfromcsv seems to have a bug that ignores any dtypes provided
I found this due to [someone's problem loading large integers with recfromcsv](http://stackoverflow.com/questions/11064908/getting-numpy-overflow-despite-declaring-dtype-int64/11065583#comment14481167_11065583). After playing with it, I think it is simply ignoring all the dtype information provided.

[Line 1859 in npyio.py, part of recfromcsv()](https://github.com/numpy/numpy/blob/master/numpy/lib/npyio.py#L1859) tries to either bring in the dtypes passed or set None. However, it actually brings in a kwarg that I couldn't find anywhere else called 'update' which looks suspiciously like a copied mistype from earlier in the line. If I change 'update' --> 'dtype', then the types get picked up as expected. More explicitly, in recfromcsv, change:

`kwargs.update(dtype=kwargs.get('update', None),`

to this:

`kwargs.update(dtype=kwargs.get('dtype', None),`

I found this in the github repo (although I may have been looking at the wrong branch) as well as the 1.6.2 release that I am using.

**_(apologies for double posting this. I [posted in trac](http://projects.scipy.org/numpy/ticket/2168) first and then heard that maybe that won't be looked at. I haven't found a way to delete or close that ticket.)**_



Discussion:

Resolving patch:
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -1844,7 +1844,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:
@@ -1871,17 +1871,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)


Test patch:
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1572,6 +1572,14 @@ def test_recfromcsv(self):
                            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