Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Allow to delete all the columns in a ctable. Fixes #306.
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescAlted committed Jun 15, 2016
1 parent 3747b2d commit e2ac48f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Release notes for bcolz
Changes from 1.1.0 to 1.1.1
===========================

#XXX version-specific blurb XXX#
- Allow to delete all the columns in a ctable. Fixes #306.


Changes from 1.0.0 to 1.1.0
Expand Down
5 changes: 3 additions & 2 deletions bcolz/ctable.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,9 @@ def delcol(self, name=None, pos=None, keep=False):
# Remove the column
col = self.cols.pop(name)

# Update _arr1 for the new dtype
self._arr1 = np.empty(shape=(1,), dtype=self.dtype)
# Update _arr1 for the new dtype (only if it is non-empty)
if self.dtype != np.dtype([]):
self._arr1 = np.empty(shape=(1,), dtype=self.dtype)

if not keep:
col.purge()
Expand Down
46 changes: 46 additions & 0 deletions bcolz/tests/test_ctable.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,52 @@ def test09b(self):
self.assertRaises(ValueError, t.__setitem__,
'f1', np.arange(N + 1, dtype='i8'))

def test10(self):
"""Testing removing two existing columns sequentially"""
N = 10
ra = np.fromiter(((i, i * 2, i * 3, i * 2.)
for i in xrange(N)), dtype='i4,i8,f4,f8')
t = bcolz.ctable(ra, rootdir=self.rootdir)
t.delcol('f2')
t.delcol('f3')
ra = np.fromiter(((i, i * 2) for i in xrange(N)), dtype='i4,i8')
ra.dtype.names = ('f0', 'f1')
# print "t->", `t`
# print "ra[:]", ra[:]
assert_array_equal(t[:], ra, "ctable values are not correct")

def test11a(self):
"""Testing removing all columns"""
N = 10
ra = np.fromiter(((i, i * 3, i * 2.)
for i in xrange(N)), dtype='i4,f4,f8')
t = bcolz.ctable(ra, rootdir=self.rootdir)
t.delcol('f0')
t.delcol('f1')
t.delcol('f2')
# print "t->", `t`
# print "ra[:]", ra[:]
assert t.dtype == np.dtype([])

def test11b(self):
"""Testing removing all columns and re-adding more"""
N = 10
ra = np.fromiter(((i, i * 3, i * 2.)
for i in xrange(N)), dtype='i4,f4,f8')
t = bcolz.ctable(ra, rootdir=self.rootdir)
t.delcol('f0')
t.delcol('f1')
t.delcol('f2')
b = np.arange(N, dtype='i4')
t.addcol(bcolz.carray(b), 'f0')
c = np.arange(N, dtype='f4') * 2
t.addcol(bcolz.carray(c), 'f1')
ra = np.fromiter(((i, i * 2) for i in xrange(N)), dtype='i4,f4')
# print "t->", `t`
# print "ra[:]", ra[:]
assert_array_equal(t[:], ra, "ctable values are not correct")


class add_del_colMemoryTest(add_del_colTest, TestCase):
disk = False

Expand Down

0 comments on commit e2ac48f

Please sign in to comment.