Repository: numpy/numpy

Issue:
`numpy.lib._iotools.StringConverter.upgrade` should have a return value
According to the documentation, routine `upgrade` should return the value of the conversion, but it does not.

`numpy.lib._iotools.StringConverter.upgrade` should have a return value
According to the documentation, routine `upgrade` should return the value of the conversion, but it does not.



Discussion:
Indeed. What is embarrassing is that it doesn't seem to cause a problem.

Indeed. What is embarrassing is that it doesn't seem to cause a problem.


Resolving patch:
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py
--- a/numpy/lib/_iotools.py
+++ b/numpy/lib/_iotools.py
@@ -27,6 +27,7 @@ def _bytes_to_name(s):
     _bytes_to_complex = complex
     _bytes_to_name = str
 
+
 def _is_string_like(obj):
     """
     Check whether obj behaves like a string.
@@ -37,6 +38,7 @@ def _is_string_like(obj):
         return False
     return True
 
+
 def _is_bytes_like(obj):
     """
     Check whether obj behaves like a bytes object.
@@ -445,6 +447,7 @@ class ConverterError(Exception):
     """
     pass
 
+
 class ConverterLockError(ConverterError):
     """
     Exception raised when an attempt is made to upgrade a locked converter.
@@ -452,6 +455,7 @@ class ConverterLockError(ConverterError):
     """
     pass
 
+
 class ConversionWarning(UserWarning):
     """
     Warning issued when a string converter has a problem.
@@ -708,7 +712,7 @@ def upgrade(self, value):
         """
         self._checked = True
         try:
-            self._strict_call(value)
+            return self._strict_call(value)
         except ValueError:
             # Raise an exception if we locked the converter...
             if self._locked:
@@ -728,7 +732,7 @@ def upgrade(self, value):
                 self.default = self._initial_default
             else:
                 self.default = default
-            self.upgrade(value)
+            return self.upgrade(value)
 
     def iterupgrade(self, value):
         self._checked = True


Test patch:
diff --git a/numpy/lib/tests/test__iotools.py b/numpy/lib/tests/test__iotools.py
--- a/numpy/lib/tests/test__iotools.py
+++ b/numpy/lib/tests/test__iotools.py
@@ -7,7 +7,7 @@
 import numpy as np
 from numpy.compat import asbytes, asbytes_nested
 from numpy.testing import (
-    run_module_suite, TestCase, assert_, assert_equal
+    run_module_suite, TestCase, assert_, assert_equal, assert_allclose
     )
 from numpy.lib._iotools import (
     LineSplitter, NameValidator, StringConverter,
@@ -76,7 +76,7 @@ def test_variable_fixed_width(self):
         test = LineSplitter((6, 6, 9))(strg)
         assert_equal(test, asbytes_nested(['1', '3  4', '5  6']))
 
-#-------------------------------------------------------------------------------
+# -----------------------------------------------------------------------------
 
 
 class TestNameValidator(TestCase):
@@ -127,7 +127,7 @@ def test_validate_wo_names(self):
         assert_(validator(namelist) is None)
         assert_equal(validator(namelist, nbfields=3), ['f0', 'f1', 'f2'])
 
-#-------------------------------------------------------------------------------
+# -----------------------------------------------------------------------------
 
 
 def _bytes_to_date(s):
@@ -150,13 +150,17 @@ def test_upgrade(self):
         "Tests the upgrade method."
         converter = StringConverter()
         assert_equal(converter._status, 0)
-        converter.upgrade(asbytes('0'))
+        # test int
+        assert_equal(converter.upgrade(asbytes('0')), 0)
         assert_equal(converter._status, 1)
-        converter.upgrade(asbytes('0.'))
+        # test float
+        assert_allclose(converter.upgrade(asbytes('0.')), 0.0)
         assert_equal(converter._status, 2)
-        converter.upgrade(asbytes('0j'))
+        # test complex
+        assert_equal(converter.upgrade(asbytes('0j')), complex('0j'))
         assert_equal(converter._status, 3)
-        converter.upgrade(asbytes('a'))
+        # test str
+        assert_equal(converter.upgrade(asbytes('a')), asbytes('a'))
         assert_equal(converter._status, len(converter._mapper) - 1)
 
     def test_missing(self):