diff options
author | f380cedric <f380cedric@users.noreply.github.com> | 2023-04-25 15:47:48 +0200 |
---|---|---|
committer | f380cedric <f380cedric@users.noreply.github.com> | 2023-04-25 15:47:48 +0200 |
commit | abfadc93082e70c2fd47412226436da448e0478c (patch) | |
tree | f6e0bdb484f52f567b7eba59d082a9b250476143 /numpy/lib/npyio.py | |
parent | a87bc1ddce6eb04a2b81fbce0c7c1471f315daf5 (diff) | |
download | numpy-abfadc93082e70c2fd47412226436da448e0478c.tar.gz |
EHN: add __contains__() to np.lib.npyio.NpzFile
NpzFile inherits from collections.abc.Mapping,
which provides __contains__().
However, it calls __getitem__(),
which can be slow because it performs file decompression on success.
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r-- | numpy/lib/npyio.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index f8f2ab7a2..22fb0eb7d 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -262,6 +262,9 @@ class NpzFile(Mapping): else: raise KeyError("%s is not a file in the archive" % key) + def __contains__(self, key): + return (key in self._files or key in self.files) + def __repr__(self): # Get filename or default to `object` if isinstance(self.fid, str): |