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

Commit

Permalink
Merge pull request #178 from brentp/ctable-strings
Browse files Browse the repository at this point in the history
allow adding strings > len 1 to ctable
  • Loading branch information
esc committed May 1, 2015
2 parents 8ce8e1a + 402edac commit 73da749
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bcolz/ctable.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def append(self, cols):
if sclist and not hasattr(column, '__len__'):
clen2 = 1
else:
clen2 = len(column)
clen2 = 1 if isinstance(column, _strtypes) else len(column)
if clen >= 0 and clen != clen2:
raise ValueError(
"all cols in `cols` must have the same length")
Expand Down
11 changes: 11 additions & 0 deletions bcolz/tests/test_ctable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,17 @@ def test_08(self):

t.flush.assert_called_with()

def test_strings(self):
"""Testing that we can add fixed length strings to a ctable"""
dtype = np.dtype([("a", "|S5"),
("b", np.uint8),
("c", np.int32),
("d", np.float32)])
t = bcolz.ctable(np.empty(0, dtype=dtype), mode="w")
t.append(("aaaaa", 23, 34567, 1.2355))
self.assertTrue(len(t) == 1)
self.assertTrue(t["a"][0] == b"aaaaa", t["a"][0])

if __name__ == '__main__':
unittest.main(verbosity=2)

Expand Down

0 comments on commit 73da749

Please sign in to comment.