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

Method test01_readCArray

tables/tests/test_carray.py:114–186  ·  view source on GitHub ↗

Checking read() of chunked layout arrays.

(self)

Source from the content-addressed store, hash-verified

112 self.assertEqual(obj.atom.type, self.type)
113
114 def test01_readCArray(self):
115 """Checking read() of chunked layout arrays."""
116
117 if common.verbose:
118 print("\n", "-=" * 30)
119 print("Running %s.test01_readCArray..." % self.__class__.__name__)
120
121 # Create an instance of an HDF5 Table
122 if self.reopen:
123 self.h5file = tb.open_file(self.h5fname, "r")
124 carray = self.h5file.get_node("/carray1")
125
126 # Choose a small value for buffer size
127 carray.nrowsinbuf = 3
128 if common.verbose:
129 print("CArray descr:", repr(carray))
130 print("shape of read array ==>", carray.shape)
131 print("reopening?:", self.reopen)
132
133 shape = self._get_shape()
134
135 # Build the array to do comparisons
136 if self.flavor == "numpy":
137 if self.type == "string":
138 object_ = np.ndarray(
139 buffer=b"a" * self.objsize,
140 shape=self.shape,
141 dtype=f"S{carray.atom.itemsize}",
142 )
143 else:
144 object_ = np.arange(self.objsize, dtype=carray.atom.dtype)
145 object_.shape = shape
146
147 stop = self.stop
148 # stop == None means read only the element designed by start
149 # (in read() contexts)
150 if self.stop is None:
151 if self.start == -1: # corner case
152 stop = carray.nrows
153 else:
154 stop = self.start + 1
155 # Protection against number of elements less than existing
156 # if rowshape[self.extdim] < self.stop or self.stop == 0:
157 if carray.nrows < stop:
158 # self.stop == 0 means last row only in read()
159 # and not in [::] slicing notation
160 stop = int(carray.nrows)
161 # do a copy() in order to ensure that len(object._data)
162 # actually do a measure of its length
163 obj = object_[self.start : stop : self.step].copy()
164
165 # Read all the array
166 try:
167 data = carray.read(self.start, stop, self.step)
168 except IndexError:
169 if self.flavor == "numpy":
170 data = np.empty(shape=self.shape, dtype=self.type)
171 else:

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