Пример #1
0
 def test07(self):
     """Testing `wherechunks` method with a `limit`, `skip` parameter"""
     N, M = int(1e4), 101
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = blz.btable(ra)
     l, s = 0, 0
     for block in blz.whereblocks(t, 'f1 < f2', limit=N-M-2, skip=M):
         l += len(block)
         s += block['f0'].sum()
     self.assert_(l == N - M - 2)
     self.assert_(s == np.arange(M+1, N-1).sum())
Пример #2
0
 def test00(self):
     """Testing `wherechunks` method with only an expression"""
     N = int(1e4)
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = blz.btable(ra)
     l, s = 0, 0
     for block in blz.whereblocks(t, 'f1 < f2'):
         l += len(block)
         s += block['f0'].sum()
     self.assert_(l == N - 1)
     self.assert_(s == (N - 1) * (N / 2))  # Gauss summation formula
Пример #3
0
 def test05(self):
     """Testing `wherechunks` method with a `limit` parameter"""
     N, M = int(1e4), 101
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = blz.btable(ra)
     l, s = 0, 0
     for block in blz.whereblocks(t, 'f1 < f2', limit=M):
         l += len(block)
         s += block['f0'].sum()
     self.assert_(l == M)
     self.assert_(s == M * ((M + 1) / 2))  # Gauss summation formula
Пример #4
0
 def test02(self):
     """Testing `wherechunks` method with a `outfields` with 2 fields"""
     N = int(1e4)
     ra = np.fromiter(((i, i, i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = blz.btable(ra)
     l, s = 0, 0
     for block in blz.whereblocks(t, 'f1 < f2', outfields=('f1','f2')):
         self.assert_(block.dtype.names == ('f1','f2'))
         l += len(block)
         s += block['f1'].sum()
     self.assert_(l == N - 1)
     self.assert_(s == (N - 1) * (N / 2))  # Gauss summation formula
Пример #5
0
 def test00(self):
     """Testing `wherechunks` method with only an expression"""
     N = int(1e4)
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = blz.btable(ra)
     l, s = 0, 0
     for block in blz.whereblocks(t, 'f1 < f2'):
         l += len(block)
         s += block['f0'].sum()
     self.assert_(l == N - 1)
     self.assert_(s == (N - 1) * (N / 2))  # Gauss summation formula
Пример #6
0
 def test07(self):
     """Testing `wherechunks` method with a `limit`, `skip` parameter"""
     N, M = int(1e4), 101
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = blz.btable(ra)
     l, s = 0, 0
     for block in blz.whereblocks(t, 'f1 < f2', limit=N - M - 2, skip=M):
         l += len(block)
         s += block['f0'].sum()
     self.assert_(l == N - M - 2)
     self.assert_(s == np.arange(M + 1, N - 1).sum())
Пример #7
0
 def test05(self):
     """Testing `wherechunks` method with a `limit` parameter"""
     N, M = int(1e4), 101
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = blz.btable(ra)
     l, s = 0, 0
     for block in blz.whereblocks(t, 'f1 < f2', limit=M):
         l += len(block)
         s += block['f0'].sum()
     self.assert_(l == M)
     self.assert_(s == M * ((M + 1) / 2))  # Gauss summation formula
Пример #8
0
 def test03(self):
     """Testing `wherechunks` method with a `outfields` with 1 field"""
     N = int(1e4)
     ra = np.fromiter(((i, i, i * 3) for i in xrange(N)), dtype='i4,f8,i8')
     t = blz.btable(ra)
     l, s = 0, 0
     for block in blz.whereblocks(t, 'f1 < f2', outfields=('f1', )):
         self.assert_(block.dtype.names == ('f1', ))
         l += len(block)
         s += block['f1'].sum()
     self.assert_(l == N - 1)
     self.assert_(s == (N - 1) * (N / 2))  # Gauss summation formula
Пример #9
0
 def test01(self):
     """Testing `wherechunks` method with a `blen`"""
     N = int(1e4)
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = blz.btable(ra)
     l, s = 0, 0
     for block in blz.whereblocks(t, 'f0 <= f1', blen=100):
         l += len(block)
         # All blocks should be of length 100, except the last one,
         # which should be 0
         self.assert_(len(block) in (0, 100))
         s += block['f0'].sum()
     self.assert_(l == N)
     self.assert_(s == (N - 1) * (N / 2))  # Gauss summation formula
Пример #10
0
 def test01(self):
     """Testing `wherechunks` method with a `blen`"""
     N = int(1e4)
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = blz.btable(ra)
     l, s = 0, 0
     for block in blz.whereblocks(t, 'f0 <= f1', blen=100):
         l += len(block)
         # All blocks should be of length 100, except the last one,
         # which should be 0
         self.assert_(len(block) in (0, 100))
         s += block['f0'].sum()
     self.assert_(l == N)
     self.assert_(s == (N - 1) * (N / 2))  # Gauss summation formula
Пример #11
0
    def wherechunks(self,
                    expression,
                    blen=None,
                    outfields=None,
                    limit=None,
                    skip=0):
        """Return chunks fulfilling `expression`.

        Iterate over the rows that fullfill the `expression` condition
        on Table `self.original` in blocks of size `blen`.

        Parameters
        ----------
        expression : string or barray
            A boolean Numexpr expression or a boolean barray.
        blen : int
            The length of the block that is returned.  The default is the
            chunklen, or for a btable, the minimum of the different column
            chunklens.
        outfields : list of strings or string
            The list of column names that you want to get back in results.
            Alternatively, it can be specified as a string such as 'f0 f1' or
            'f0, f1'.  If None, all the columns are returned.
        limit : int
            A maximum number of elements to return.  The default is return
            everything.
        skip : int
            An initial number of elements to skip.  The default is 0.

        Returns
        -------
        out : iterable
            This iterable returns buffers as NumPy arrays made of
            structured types (or homogeneous ones in case `outfields` is a
            single field.

        See Also
        --------
        iterchunks

        """
        # Return the iterable
        return blz.whereblocks(self.blzarr, expression, blen, outfields, limit,
                               skip)
Пример #12
0
    def wherechunks(self, expression, blen=None, outfields=None, limit=None,
                    skip=0):
        """Return chunks fulfilling `expression`.

        Iterate over the rows that fullfill the `expression` condition
        on Table `self.original` in blocks of size `blen`.

        Parameters
        ----------
        expression : string or barray
            A boolean Numexpr expression or a boolean barray.
        blen : int
            The length of the block that is returned.  The default is the
            chunklen, or for a btable, the minimum of the different column
            chunklens.
        outfields : list of strings or string
            The list of column names that you want to get back in results.
            Alternatively, it can be specified as a string such as 'f0 f1' or
            'f0, f1'.  If None, all the columns are returned.
        limit : int
            A maximum number of elements to return.  The default is return
            everything.
        skip : int
            An initial number of elements to skip.  The default is 0.

        Returns
        -------
        out : iterable
            This iterable returns buffers as NumPy arrays made of
            structured types (or homogeneous ones in case `outfields` is a
            single field.

        See Also
        --------
        iterchunks

        """
        # Return the iterable
        return blz.whereblocks(self.blzarr, expression, blen, outfields,
                               limit, skip)