Skip to content

Commit

Permalink
Fix writing of booleans (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe authored May 28, 2019
1 parent e4030e3 commit 26edb67
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ctapipe/io/hdf5tableio.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"uint16": tables.UInt16Col,
"uint32": tables.UInt32Col,
"uint64": tables.UInt64Col,
"bool": tables.UInt8Col,
"bool": tables.BoolCol,
}


Expand Down
28 changes: 24 additions & 4 deletions ctapipe/io/tests/test_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def test_prefix(tmp_path):

def test_write_containers(temp_h5_file):
class C1(Container):
a = Field("a", None)
b = Field("b", None)
a = Field(None, "a")
b = Field(None, "b")

class C2(Container):
c = Field("c", None)
d = Field("d", None)
c = Field(None, "c")
d = Field(None, "d")

with tempfile.NamedTemporaryFile() as f:
with HDF5TableWriter(f.name, "test") as writer:
Expand All @@ -90,6 +90,26 @@ class C2(Container):
writer.write("tel_001", [c1, c2])


def test_write_bool():
class C(Container):
boolean = Field(True, 'Boolean value')

with tempfile.NamedTemporaryFile() as f:
with HDF5TableWriter(f.name, "test") as writer:
for i in range(2):
c = C(boolean=(i % 2 == 0))
writer.write("c", c)

c = C()
with HDF5TableReader(f.name) as reader:
c_reader = reader.read('/test/c', c)
for i in range(2):
cur = next(c_reader)
expected = (i % 2) == 0
assert isinstance(cur.boolean, np.bool_)
assert cur.boolean == expected


def test_read_container(temp_h5_file):
r0tel1 = R0CameraContainer()
r0tel2 = R0CameraContainer()
Expand Down

0 comments on commit 26edb67

Please sign in to comment.