Skip to content

Commit

Permalink
BUG: ticket #1428, allow int64 and uint64 integer types to be specifi…
Browse files Browse the repository at this point in the history
…ed in

genfromtxt.
  • Loading branch information
charris committed Apr 2, 2011
1 parent 32903b3 commit ad7cb17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 8 additions & 2 deletions numpy/lib/_iotools.py
Expand Up @@ -600,9 +600,15 @@ def __init__(self, dtype_or_func=None, default=None, missing_values=None,
# 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('')])
Expand Down
16 changes: 16 additions & 0 deletions numpy/lib/tests/test__iotools.py
Expand Up @@ -218,6 +218,20 @@ def test_keep_missing_values(self):
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):
Expand Down Expand Up @@ -309,3 +323,5 @@ def test_flatten_dtype(self):
dt_flat = flatten_dtype(dt)
assert_equal(dt_flat, [float, float])

if __name__ == "__main__":
run_module_suite()

0 comments on commit ad7cb17

Please sign in to comment.