summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2023-04-25 12:56:06 -0400
committerGitHub <noreply@github.com>2023-04-25 12:56:06 -0400
commit54e4dbe4d07294bbf32f3fca2425faf180bed289 (patch)
treed2576f82cc37f57e7a1512c4dbc6bf884f3f69e9
parente1b1a5222b0635b8fa08d2b7a1524163c546174f (diff)
parentabfadc93082e70c2fd47412226436da448e0478c (diff)
downloadnumpy-54e4dbe4d07294bbf32f3fca2425faf180bed289.tar.gz
Merge pull request #23661 from f380cedric/npzfile-contains
EHN: add __contains__() to np.lib.npyio.NpzFile
-rw-r--r--numpy/lib/npyio.py3
-rw-r--r--numpy/lib/npyio.pyi1
2 files changed, 4 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):
diff --git a/numpy/lib/npyio.pyi b/numpy/lib/npyio.pyi
index 9dd3d6809..cc81e82b7 100644
--- a/numpy/lib/npyio.pyi
+++ b/numpy/lib/npyio.pyi
@@ -98,6 +98,7 @@ class NpzFile(Mapping[str, NDArray[Any]]):
def __iter__(self) -> Iterator[str]: ...
def __len__(self) -> int: ...
def __getitem__(self, key: str) -> NDArray[Any]: ...
+ def __contains__(self, key: str) -> bool: ...
def __repr__(self) -> str: ...
# NOTE: Returns a `NpzFile` if file is a zip file;