MCPcopy Create free account
hub / github.com/numpy/numpy / __getitem__

Method __getitem__

numpy/lib/npyio.py:235–263  ·  view source on GitHub ↗
(self, key)

Source from the content-addressed store, hash-verified

233 return len(self.files)
234
235 def __getitem__(self, key):
236 # FIXME: This seems like it will copy strings around
237 # more than is strictly necessary. The zipfile
238 # will read the string and then
239 # the format.read_array will copy the string
240 # to another place in memory.
241 # It would be better if the zipfile could read
242 # (or at least uncompress) the data
243 # directly into the array memory.
244 member = False
245 if key in self._files:
246 member = True
247 elif key in self.files:
248 member = True
249 key += '.npy'
250 if member:
251 bytes = self.zip.open(key)
252 magic = bytes.read(len(format.MAGIC_PREFIX))
253 bytes.close()
254 if magic == format.MAGIC_PREFIX:
255 bytes = self.zip.open(key)
256 return format.read_array(bytes,
257 allow_pickle=self.allow_pickle,
258 pickle_kwargs=self.pickle_kwargs,
259 max_header_size=self.max_header_size)
260 else:
261 return self.zip.read(key)
262 else:
263 raise KeyError(f"{key} is not a file in the archive")
264
265 def __contains__(self, key):
266 return (key in self._files or key in self.files)

Callers

nothing calls this directly

Calls 3

openMethod · 0.45
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected