Beispiel #1
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)
Beispiel #2
0
    def testFormatsFromDescr(self):
        """Retrieves the formats list from the descr list.
        """

        # Check getFormatsFromDescr function
        new_formats = \
            [f for f in nriterators.getFormatsFromDescr(self.descr)]
        self.assertEqual(self.formats, new_formats)
Beispiel #3
0
    def testFormatsFromDescr(self):
        """Retrieves the formats list from the descr list.
        """

        # Check getFormatsFromDescr function
        new_formats = \
            [f for f in nriterators.getFormatsFromDescr(self.descr)]
        self.assertEqual(self.formats, new_formats)
Beispiel #4
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)
Beispiel #5
0
def makeFormats(descr):
    """Create a ``formats`` list for the array."""

    return [item for item in nriterators.getFormatsFromDescr(descr)]
Beispiel #6
0
def makeFormats(descr):
    """Create a ``formats`` list for the array."""

    return [item for item in nriterators.getFormatsFromDescr(descr)]