Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 70559bc

Browse files
authored
test for completely empty datasets (#281)
* test for completely empty datasets * prevents failures with cryptic error message: HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 140737340061504: #000: ../../../src/H5Shyper.c line 7057 in H5Sselect_hyperslab(): hyperslab doesn't support H5S_NULL space
1 parent 5932272 commit 70559bc

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/population.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ namespace sonata {
2929

3030
namespace {
3131

32-
const char* H5_DYNAMICS_PARAMS = "dynamics_params";
33-
const char* H5_LIBRARY = "@library";
32+
constexpr const char* const H5_DYNAMICS_PARAMS = "dynamics_params";
33+
constexpr const char* const H5_LIBRARY = "@library";
3434

3535

3636
std::set<std::string> _listChildren(const HighFive::Group& group,
3737
const std::set<std::string>& ignoreNames = {}) {
3838
std::set<std::string> result;
3939
for (const auto& name : group.listObjectNames()) {
40-
if (ignoreNames.count(name)) {
40+
if (ignoreNames.count(name) > 0) {
4141
continue;
4242
}
4343
result.insert(name);
@@ -57,7 +57,6 @@ std::set<std::string> _listExplicitEnumerations(const HighFive::Group h5Group,
5757
return names;
5858
}
5959

60-
6160
template <typename T>
6261
std::vector<T> _readChunk(const HighFive::DataSet& dset, const Selection::Range& range) {
6362
std::vector<T> result;
@@ -70,6 +69,10 @@ std::vector<T> _readChunk(const HighFive::DataSet& dset, const Selection::Range&
7069

7170
template <typename T, typename std::enable_if<!std::is_pod<T>::value>::type* = nullptr>
7271
std::vector<T> _readSelection(const HighFive::DataSet& dset, const Selection& selection) {
72+
if (selection.ranges().empty() || dset.getElementCount() == 0) {
73+
return {};
74+
}
75+
7376
if (selection.ranges().size() == 1) {
7477
return _readChunk<T>(dset, selection.ranges().front());
7578
}
@@ -89,7 +92,7 @@ std::vector<T> _readSelection(const HighFive::DataSet& dset, const Selection& se
8992

9093
template <typename T, typename std::enable_if<std::is_pod<T>::value>::type* = nullptr>
9194
std::vector<T> _readSelection(const HighFive::DataSet& dset, const Selection& selection) {
92-
if (selection.ranges().empty()) {
95+
if (selection.ranges().empty() || dset.getElementCount() == 0) {
9396
return {};
9497
} else if (selection.ranges().size() == 1) {
9598
return _readChunk<T>(dset, selection.ranges().front());

tests/test_nodes.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ TEST_CASE("NodePopulationSelectAll", "[base]") {
163163
TEST_CASE("NodePopulationmatchAttributeValues", "[base]") {
164164
NodePopulation population("./data/nodes1.h5", "", "nodes-A");
165165

166+
SECTION("int") {
167+
const auto sel = population.matchAttributeValues("A-int64", 1);
168+
CHECK(sel.flatSize() == 0);
169+
170+
CHECK_THROWS_AS(population.matchAttributeValues("E-mapping-good", 1), SonataError);
171+
}
172+
166173
SECTION("String") {
167174
auto sel = population.matchAttributeValues<std::string>("attr-Z", "bb");
168175
CHECK(sel.flatSize() == 1);

0 commit comments

Comments
 (0)