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

Method test01_readCArray_out_argument

tables/tests/test_carray.py:188–247  ·  view source on GitHub ↗

Checking read() of chunked layout arrays.

(self)

Source from the content-addressed store, hash-verified

186 self.assertTrue(common.allequal(data, obj, self.flavor))
187
188 def test01_readCArray_out_argument(self):
189 """Checking read() of chunked layout arrays."""
190
191 # Create an instance of an HDF5 Table
192 if self.reopen:
193 self.h5file = tb.open_file(self.h5fname, "r")
194 carray = self.h5file.get_node("/carray1")
195
196 shape = self._get_shape()
197
198 # Choose a small value for buffer size
199 carray.nrowsinbuf = 3
200 # Build the array to do comparisons
201 if self.flavor == "numpy":
202 if self.type == "string":
203 object_ = np.ndarray(
204 buffer=b"a" * self.objsize,
205 shape=self.shape,
206 dtype=f"S{carray.atom.itemsize}",
207 )
208 else:
209 object_ = np.arange(self.objsize, dtype=carray.atom.dtype)
210 object_.shape = shape
211
212 stop = self.stop
213 # stop == None means read only the element designed by start
214 # (in read() contexts)
215 if self.stop is None:
216 if self.start == -1: # corner case
217 stop = carray.nrows
218 else:
219 stop = self.start + 1
220 # Protection against number of elements less than existing
221 # if rowshape[self.extdim] < self.stop or self.stop == 0:
222 if carray.nrows < stop:
223 # self.stop == 0 means last row only in read()
224 # and not in [::] slicing notation
225 stop = int(carray.nrows)
226 # do a copy() in order to ensure that len(object._data)
227 # actually do a measure of its length
228 obj = object_[self.start : stop : self.step].copy()
229
230 # Read all the array
231 try:
232 data = np.empty(shape, dtype=carray.atom.dtype)
233 data = data[self.start : stop : self.step].copy()
234 carray.read(self.start, stop, self.step, out=data)
235 except IndexError:
236 if self.flavor == "numpy":
237 data = np.empty(shape=shape, dtype=self.type)
238 else:
239 data = np.empty(shape=shape, dtype=self.type)
240
241 if hasattr(data, "shape"):
242 self.assertEqual(len(data.shape), len(shape))
243 else:
244 # Scalar case
245 self.assertEqual(len(shape), 1)

Callers

nothing calls this directly

Calls 4

_get_shapeMethod · 0.95
get_nodeMethod · 0.45
copyMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected