Allow empty slice when loading log with sublogs#299
Conversation
| if isinstance(select, tuple) and len(select) == 0: | ||
| return {} | ||
| if select == slice(None, None, None): | ||
| check_1d() |
There was a problem hiding this comment.
Why is the branch below that does elif isinstance(select, int | sc.Variable) or isinstance(select, slice): not sufficient?
There was a problem hiding this comment.
Because that returns a 1d slice which leads to this error downstream:
59 def read_children(self, sel: ScippIndex) -> sc.DataGroup:
60 # Sublogs have distinct time axes (with a different length). Must disable
61 # positional indexing.
62 if self._sublogs and ('time' in to_canonical_select(list(self.sizes), sel)):
---> 63 raise sc.DimensionError(
64 "Cannot positionally select time since there are multiple "
65 "time fields. Label-based selection is not supported yet."
66 )
67 dg = super().read_children(sel)
68 for name, field in self._sublog_children.items():
DimensionError: Cannot positionally select time since there are multiple time fields. Label-based selection is not supported yet.
scippnexus/src/scippnexus/nxlog.py
Lines 59 to 70 in 1ca907d
Alternatively, we could change the check here.
There was a problem hiding this comment.
Right, so this specifically fixes a bug when the ESS-style "sublogs" are present (which are not in the standard, iirc)? A more targeted fix might indeed make sense, but I don't mind too much.
Can you update the PR title/description?
I think this also means that the new tests do not really do much that didn't work before, as they contain no sublogs as far as I can see. The removed line in test_log_with_connection_status_raises_with_positional_and_label_indexing is I think the test you actually need, except that it would now not raise.
16102e9 to
19fafcd
Compare
Loading an NXlog that contians sublogs with
x[:]raises an exception because we don't support slicing sublogs. But in this case, it should behave the same asx[()]orx[...]for 1D data. So this PR handles it this way.I ran into this in ESSreduce when passing the default
TimeInterval(slice(None, None, None)) to a loader for an NXlog.