fhs / NPZ.jl

A Julia package that provides support for reading and writing Numpy .npy and .npz files
Other
119 stars 16 forks source link

Deal with "long integers" like "1024L" in shape #11

Closed amilsted closed 8 years ago

amilsted commented 8 years ago

Thanks for making NPZ! Nice to be able to use my numpy data so easily :)

Unfortunately, I noticed a small problem:

On some systems, the shape of an array looks like (1024L, 1024L) rather than (1024, 1024), indicating the use of long integers. This is the case on my Anaconda installation on Windows, for example. See also this.

This is also true in the header of generated npy files. For example: {'descr': '<c16', 'fortran_order': False, 'shape': (3L, 32L, 32L), }

It would be nice if NPZ would handle this case too!

amilsted commented 8 years ago

Here's the needed change.

diff --git a/src/NPZ.jl b/src/NPZ.jl
index 0d280b8..009f34f 100644
--- a/src/NPZ.jl
+++ b/src/NPZ.jl
@@ -83,6 +83,9 @@ end
 function parseinteger(s::ASCIIString)
    i = findfirst(c -> !isdigit(c), s)
    n = parse(Int, s[1:i-1])
+   if s[i] == 'L'
+       i += 1
+   end
    n, s[i:end]
 end