MCPcopy Create free account
hub / github.com/PyTables/PyTables / test02_getitemCArray

Method test02_getitemCArray

tables/tests/test_carray.py:249–311  ·  view source on GitHub ↗

Checking chunked layout array __getitem__ special method.

(self)

Source from the content-addressed store, hash-verified

247 self.assertTrue(common.allequal(data, obj, self.flavor))
248
249 def test02_getitemCArray(self):
250 """Checking chunked layout array __getitem__ special method."""
251
252 if common.verbose:
253 print("\n", "-=" * 30)
254 print(
255 "Running %s.test02_getitemCArray..." % self.__class__.__name__
256 )
257
258 if not hasattr(self, "slices"):
259 # If there is not a slices attribute, create it
260 self.slices = (slice(self.start, self.stop, self.step),)
261
262 # Create an instance of an HDF5 Table
263 if self.reopen:
264 self.h5file = tb.open_file(self.h5fname, "r")
265 carray = self.h5file.get_node("/carray1")
266
267 if common.verbose:
268 print("CArray descr:", repr(carray))
269 print("shape of read array ==>", carray.shape)
270 print("reopening?:", self.reopen)
271
272 shape = self._get_shape()
273
274 # Build the array to do comparisons
275 if self.type == "string":
276 object_ = np.ndarray(
277 buffer=b"a" * self.objsize,
278 shape=self.shape,
279 dtype=f"S{carray.atom.itemsize}",
280 )
281 else:
282 object_ = np.arange(self.objsize, dtype=carray.atom.dtype)
283 object_.shape = shape
284
285 # do a copy() in order to ensure that len(object._data)
286 # actually do a measure of its length
287 obj = object_.__getitem__(self.slices).copy()
288
289 # Read data from the array
290 try:
291 data = carray.__getitem__(self.slices)
292 except IndexError:
293 print("IndexError!")
294 if self.flavor == "numpy":
295 data = np.empty(shape=self.shape, dtype=self.type)
296 else:
297 data = np.empty(shape=self.shape, dtype=self.type)
298
299 if common.verbose:
300 print("Object read:\n", repr(data)) # , data.info()
301 print("Should look like:\n", repr(obj)) # , object.info()
302 if hasattr(obj, "shape"):
303 print("Original object shape:", self.shape)
304 print("Shape read:", data.shape)
305 print("shape should look as:", obj.shape)
306

Callers

nothing calls this directly

Calls 4

_get_shapeMethod · 0.95
get_nodeMethod · 0.45
copyMethod · 0.45
__getitem__Method · 0.45

Tested by

no test coverage detected