Skip to content

Commit

Permalink
Keep the experiment identifiers map when slicing a reflection table. (#…
Browse files Browse the repository at this point in the history
…2371)

Fixes #2276
  • Loading branch information
jbeilstenedmands committed Mar 16, 2023
1 parent ca1567f commit f2aaec4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions newsfragments/2371.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keep the experiment identifiers map when slicing a reflection table
14 changes: 14 additions & 0 deletions src/dials/array_family/boost_python/flex_table_suite.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,20 @@ namespace dials { namespace af { namespace boost_python { namespace flex_table_s
copy_to_slice_visitor<T> visitor(result, it->first, as);
it->second.apply_visitor(visitor);
}
if (self.contains("id")) {
/* note some tables contain id values of -1 for unindexed reflections
but the identifiers map only allows keys of type size_t
*/
af::shared<int> col = result["id"];
std::set<int> new_ids(col.begin(), col.end());
typedef typename T::experiment_map_type::iterator iterator;
for (std::set<int>::iterator i = new_ids.begin(); i != new_ids.end(); ++i) {
iterator found = self.experiment_identifiers()->find(*i);
if (found != self.experiment_identifiers()->end()) {
(*result.experiment_identifiers())[found->first] = found->second;
}
}
}
return result;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/array_family/test_reflection_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ def test_delete():
assert table.ncols() == 2


def test_slice():
table = flex.reflection_table()
table["col1"] = flex.int([0, 0, 1, 2, 3, 4, 5])
table["id"] = flex.int([-1, 0, 1, 2, 3, 4, 5])
for i in range(0, 6):
table.experiment_identifiers()[i] = str(i)
sliced = table[4:]
assert sliced.nrows() == 3
assert dict(sliced.experiment_identifiers()) == {3: "3", 4: "4", 5: "5"}


def test_row_operations():
# The columns as lists
c1 = list(range(10))
Expand Down

0 comments on commit f2aaec4

Please sign in to comment.