diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/lib/_iotools.py | 10 | ||||
-rw-r--r-- | numpy/lib/tests/test__iotools.py | 16 |
2 files changed, 24 insertions, 2 deletions
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py index 0bef8e5b9..dec0f5a27 100644 --- a/numpy/lib/_iotools.py +++ b/numpy/lib/_iotools.py @@ -600,9 +600,15 @@ class StringConverter: # If the input was a dtype, set the function to the last we saw if self.func is None: self.func = func - # If the status is 1 (int), change the function to smthg more robust + # If the status is 1 (int), change the function to + # something more robust. if self.func == self._mapper[1][1]: - self.func = lambda x : int(float(x)) + if issubclass(ttype, np.uint64): + self.func = np.uint64 + elif issubclass(ttype, np.int64): + self.func = np.int64 + else: + self.func = lambda x : int(float(x)) # Store the list of strings corresponding to missing values. if missing_values is None: self.missing_values = set([asbytes('')]) diff --git a/numpy/lib/tests/test__iotools.py b/numpy/lib/tests/test__iotools.py index 544057e3a..853d06087 100644 --- a/numpy/lib/tests/test__iotools.py +++ b/numpy/lib/tests/test__iotools.py @@ -218,6 +218,20 @@ class TestStringConverter(TestCase): missing_values=asbytes("N/A")) assert_equal(converter.missing_values, set(asbytes_nested(['', 'N/A']))) + def test_int64_dtype(self): + "Check that int64 integer types can be specified" + converter = StringConverter(np.int64, default=0) + val = asbytes("-9223372036854775807") + assert_(converter(val) == -9223372036854775807) + val = asbytes("9223372036854775807") + assert_(converter(val) == 9223372036854775807) + + def test_uint64_dtype(self): + "Check that uint64 integer types can be specified" + converter = StringConverter(np.uint64, default=0) + val = asbytes("9223372043271415339") + assert_(converter(val) == 9223372043271415339) + #------------------------------------------------------------------------------- class TestMiscFunctions(TestCase): @@ -309,3 +323,5 @@ class TestMiscFunctions(TestCase): dt_flat = flatten_dtype(dt) assert_equal(dt_flat, [float, float]) +if __name__ == "__main__": + run_module_suite() |