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

Method test03_setitemCArray

tables/tests/test_carray.py:313–393  ·  view source on GitHub ↗

Checking chunked layout array __setitem__ special method.

(self)

Source from the content-addressed store, hash-verified

311 self.assertTrue(common.allequal(data, obj, self.flavor))
312
313 def test03_setitemCArray(self):
314 """Checking chunked layout array __setitem__ special method."""
315
316 if common.verbose:
317 print("\n", "-=" * 30)
318 print(
319 "Running %s.test03_setitemCArray..." % self.__class__.__name__
320 )
321
322 if not hasattr(self, "slices"):
323 # If there is not a slices attribute, create it
324 self.slices = (slice(self.start, self.stop, self.step),)
325
326 # Create an instance of an HDF5 Table
327 if self.reopen:
328 self.h5file = tb.open_file(self.h5fname, "a")
329 carray = self.h5file.get_node("/carray1")
330
331 if common.verbose:
332 print("CArray descr:", repr(carray))
333 print("shape of read array ==>", carray.shape)
334 print("reopening?:", self.reopen)
335
336 shape = self._get_shape()
337
338 # Build the array to do comparisons
339 if self.type == "string":
340 object_ = np.ndarray(
341 buffer=b"a" * self.objsize,
342 shape=self.shape,
343 dtype=f"S{carray.atom.itemsize}",
344 )
345 else:
346 object_ = np.arange(self.objsize, dtype=carray.atom.dtype)
347 object_.shape = shape
348
349 # do a copy() in order to ensure that len(object._data)
350 # actually do a measure of its length
351 obj = object_.__getitem__(self.slices).copy()
352
353 if self.type == "string":
354 if hasattr(self, "wslice"):
355 obj[self.wslize] = "xXx"
356 carray[self.wslice] = "xXx"
357 elif sum(obj[self.slices].shape) != 0:
358 obj[:] = "xXx"
359 if obj.size > 0:
360 carray[self.slices] = obj
361 else:
362 if hasattr(self, "wslice"):
363 obj[self.wslice] = obj[self.wslice] * 2 + 3
364 carray[self.wslice] = carray[self.wslice] * 2 + 3
365 elif sum(obj[self.slices].shape) != 0:
366 obj = obj * 2 + 3
367 if np.prod(obj.shape) > 0:
368 carray[self.slices] = carray[self.slices] * 2 + 3
369 # Cast again object to its original type
370 obj = np.array(obj, dtype=carray.atom.dtype)

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