Exemple #1
0
    def testDescrStructure(self):
        """Check structure of the descr list.
        """

        common.verbosePrint('\nTesting descr structure')
        for item in nriterators.flattenDescr(self.descr, check=True):
            self.failIfEqual(item, None)
    def testDescrStructure(self):
        """Check structure of the descr list.
        """

        common.verbosePrint('\nTesting descr structure')
        for item in nriterators.flattenDescr(self.descr, check=True):
            self.failIfEqual(item, None)
Exemple #3
0
def fromnumpy(array):
    """
    Create a new instance of a `RecArray` from NumPy `array`.

    If nested records are present, a `NestedRecArray` is returned.  The
    input `array` must be a NumPy array or record (it is not checked).
    """
    # Convert the original description based in the array protocol in
    # something that can be understood by the NestedRecArray
    # constructor.
    descr = [i for i in convertFromAPDescr(array.dtype.descr)]
    # Flat the description
    flatDescr = [i for i in nriterators.flattenDescr(descr)]
    # Flat the structure descriptors
    flatFormats = [i for i in nriterators.getFormatsFromDescr(flatDescr)]
    flatNames = [i for i in nriterators.getNamesFromDescr(flatDescr)]
    # Create a regular RecArray
    if array.shape == ():
        shape = 1  # Scalar case. Shape = 1 will provide an adequate buffer.
    else:
        shape = array.shape
    rarray = numarray.records.array(
        array.data, formats=flatFormats, names=flatNames, shape=shape, byteorder=sys.byteorder, aligned=False
    )  # aligned RecArrays are not supported yet

    # A ``NestedRecArray`` is only needed if there are nested fields.
    # This check has been disabled because a NestedRecArray does offer
    # more features that the users of PyTables 1.x are used to, most
    # specially, the __getitem__(fieldname) special method.
    #     if '/' in ''.join(flatNames):
    #         return NestedRecArray(rarray, descr)
    #     return rarray
    return NestedRecArray(rarray, descr)
Exemple #4
0
def _checkDescr(descr):
    """
    Check the format of the `descr` list.

    For an explanation of argument meanings see the `array()` function.
    """

    # descr must be a list
    if not isinstance(descr, list):
        raise TypeError("""the descr argument must be a list!""")

    # descr must be a list of 2-tuples
    for item in nriterators.flattenDescr(descr, check=True):
        if item is None:
            raise TypeError("""elements of the `descr` list must be 2-tuples!""")
Exemple #5
0
def _checkDescr(descr):
    """
    Check the format of the `descr` list.

    For an explanation of argument meanings see the `array()` function.
    """

    # descr must be a list
    if not isinstance(descr, list):
        raise TypeError("""the descr argument must be a list!""")

    # descr must be a list of 2-tuples
    for item in nriterators.flattenDescr(descr, check=True):
        if item is None:
            raise TypeError(
                """elements of the `descr` list must be 2-tuples!""")
Exemple #6
0
def fromnumpy(array):
    """
    Create a new instance of a `RecArray` from NumPy `array`.

    If nested records are present, a `NestedRecArray` is returned.  The
    input `array` must be a NumPy array or record (it is not checked).
    """
    # Convert the original description based in the array protocol in
    # something that can be understood by the NestedRecArray
    # constructor.
    descr = [i for i in convertFromAPDescr(array.dtype.descr)]
    # Flat the description
    flatDescr = [i for i in nriterators.flattenDescr(descr)]
    # Flat the structure descriptors
    flatFormats = [i for i in nriterators.getFormatsFromDescr(flatDescr)]
    flatNames = [i for i in nriterators.getNamesFromDescr(flatDescr)]
    # Create a regular RecArray
    if array.shape == ():
        shape = 1  # Scalar case. Shape = 1 will provide an adequate buffer.
    else:
        shape = array.shape
    rarray = numarray.records.array(
        array.data,
        formats=flatFormats,
        names=flatNames,
        shape=shape,
        byteorder=sys.byteorder,
        aligned=False)  # aligned RecArrays are not supported yet

    # A ``NestedRecArray`` is only needed if there are nested fields.
    # This check has been disabled because a NestedRecArray does offer
    # more features that the users of PyTables 1.x are used to, most
    # specially, the __getitem__(fieldname) special method.
    #     if '/' in ''.join(flatNames):
    #         return NestedRecArray(rarray, descr)
    #     return rarray
    return NestedRecArray(rarray, descr)