Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest to add string support #33

Open
ascetic168 opened this issue Apr 18, 2019 · 3 comments
Open

Suggest to add string support #33

ascetic168 opened this issue Apr 18, 2019 · 3 comments

Comments

@ascetic168
Copy link

In Numpy, string array to npz file is legal. "np.savez_compressed" in Python works fine.
ex: something like ["name1" "name2" "name3"]

So far, NPZ.jl can not read/write such kind of data. Would you like to add the support?

@bjarthur
Copy link

how can i help with adding string support?

@bjarthur
Copy link

seems non-trivial as numpy's dtype includes the length of the string (e.g. U18 for 18 characters of unicode) and so the dictionary used by NPZ.jl to convert to a julia type would have to be reworked. ugh.

@bjarthur
Copy link

in the meantime, reading what is supported helps my use case:

diff --git a/src/NPZ.jl b/src/NPZ.jl
index 39ccbc1..6babc7e 100644
--- a/src/NPZ.jl
+++ b/src/NPZ.jl
@@ -262,7 +262,11 @@ function npzread(dir::ZipFile.Reader)
         if endswith(name, ".npy")
             name = name[1:end-4]
         end
-        vars[name] = npzreadarray(f)
+        try
+            vars[name] = npzreadarray(f)
+        catch
+            @warn string("unable to read variable ",name)
+        end
     end
     vars
 end

if you like, i could work this up to include proper exceptions and submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants