Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix writing of booleans, fixes #1082 #1083

Merged
merged 1 commit into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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