def testBufferStructureWDescr(self): """Check the structure of a buffer row using the descr list. """ common.verbosePrint('\nTesting buffer row structure with zipBufferDescr') mix = [item for item in nriterators.zipBufferDescr(self.row, self.descr)] self.assertEqual(mix, zip(self.flat_row, self.flat_formats))
def testBufferStructureWDescr(self): """Check the structure of a buffer row using the descr list. """ common.verbosePrint( '\nTesting buffer row structure with zipBufferDescr') mix = [ item for item in nriterators.zipBufferDescr(self.row, self.descr) ] self.assertEqual(mix, zip(self.flat_row, self.flat_formats))
def _checkBufferStructure(structure, buffer): """ Check the `buffer` structure using the given `structure`. The checking is done after flattening both the `structure` and the `buffer`. `structure` is the descr list that describes the buffer structure. buffer` has its usual meaning in this module. """ for row in buffer: for item in nriterators.zipBufferDescr(row, structure): if not (isinstance(item, tuple) and len(item) == 2): raise ValueError("""row structure doesn't match that """ """provided by the format specification""") if not isinstance(item[1], str): raise TypeError("""field descriptors must be strings""")
formats=formats, shape=shape, names=names, byteorder=byteorder, aligned=aligned) elif buffer: _checkBufferStructure(descr, buffer) # Flatten the buffer (if any) if buffer is None: flatBuffer = None else: # Buffer is a list of sequences. Every sublist represents a row # of the array flatBuffer = \ [tuple([v for (v, f) in nriterators.zipBufferDescr(row, descr)]) for row in buffer] # Create a flat recarray flatArray = numarray.records.array(flatBuffer, flatFormats, shape, flatNames, byteorder, aligned) # Create the nested recarray return NestedRecArray(flatArray, descr) def _checkArrayList(arrayList): """ Check the type of the arraylist argument of fromarrays. For an explanation of argument meanings see the `array()` function.
flatNames = [item for item in nriterators.flattenNames(names)] # Check the buffer structure (order matters!) if isinstance(buffer, list) or isinstance(buffer, tuple): if isinstance(buffer[0], numarray.NumArray) or isinstance(buffer[0], numarray.strings.CharArray): return fromarrays(buffer, formats=formats, shape=shape, names=names, byteorder=byteorder, aligned=aligned) elif buffer: _checkBufferStructure(descr, buffer) # Flatten the buffer (if any) if buffer is None: flatBuffer = None else: # Buffer is a list of sequences. Every sublist represents a row # of the array flatBuffer = [tuple([v for (v, f) in nriterators.zipBufferDescr(row, descr)]) for row in buffer] # Create a flat recarray flatArray = numarray.records.array(flatBuffer, flatFormats, shape, flatNames, byteorder, aligned) # Create the nested recarray return NestedRecArray(flatArray, descr) def _checkArrayList(arrayList): """ Check the type of the arraylist argument of fromarrays. For an explanation of argument meanings see the `array()` function. """
if (isinstance(buffer[0], numarray.NumArray) or isinstance(buffer[0], numarray.strings.CharArray)): return fromarrays(buffer, formats=formats, shape=shape, names=names, byteorder=byteorder, aligned=aligned) elif buffer: _checkBufferStructure( descr, buffer) # Flatten the buffer (if any) if buffer is None: flatBuffer = None else: # Buffer is a list of sequences. Every sublist represents a row # of the array flatBuffer = \ [tuple([v for (v, f) in nriterators.zipBufferDescr(row, descr)]) for row in buffer] # Create a flat recarray flatArray = numarray.records.array( flatBuffer, flatFormats, shape, flatNames, byteorder, aligned) # Create the nested recarray return NestedRecArray(flatArray, descr) def _checkArrayList(arrayList): """ Check the type of the arraylist argument of fromarrays. For an explanation of argument meanings see the `array()` function.