-
-
Notifications
You must be signed in to change notification settings - Fork 12.3k
BUG: numpy.savez_compressed ignores arrays named "like" #23365
Description
Describe the issue:
If you call numpy.savez_compressed with the keyword like, i.e. if one of the named arrays is named "like", it does not get saved to the npz file. Nothing like this is documented in the savez_compressed documentation. I didn't see an issue that discussed this.
You can unzip the npz to verify that the array isn't being saved.
This seems to have started happening somewhere between numpy==1.19.5 and numpy==1.21.6. That is, numpy==1.19.5 would correctly save the array named "like". Below I used numpy==1.23.2 and I've also tried numpy==1.24.2 which behave the same as each other.
I suspect savez_compressed isn't the only affected function and "like" isn't the only relevant keyword, but I haven't explored this.
While I'd prefer input to savez_compressed to not just be silently ignored, I'd also be okay with just a documentation update to the relevant functions that explained which keywords couldn't be used.
Reproduce the code example:
import numpy as np
print(f"numpy.version.full_version={np.version.full_version}")
inputs = {
"foo": np.array([1], dtype=np.float32),
"like": np.array([2], dtype=np.float32),
}
print(inputs)
np.savez_compressed("example.npz", **inputs)
loaded_inputs = np.load("example.npz", allow_pickle=True)
print(dict(loaded_inputs))
if inputs != dict(loaded_inputs):
print("Unexpected mismatch")Error message:
No response
Runtime information:
1.23.2
3.10.9 (main, Dec 19 2022, 17:35:49) [GCC 12.2.0]
Context for the issue:
I would say silently and unexpectedly failing to save a user's output is a compelling enough reason. That said, in my case I can't simply use a different name as the names are being provided by a third party piece of code.