Skip to content

Commit

Permalink
BugFix: Fix map with 0D Ragged for non lazy signals
Browse files Browse the repository at this point in the history
  • Loading branch information
CSSFrancis committed May 27, 2024
1 parent 3612fde commit f0aac04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hyperspy/_signals/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ def rechunk(self, nav_chunks="auto", sig_chunks=-1, inplace=True, **kwargs):
if not isinstance(sig_chunks, tuple):
sig_chunks = (sig_chunks,) * len(self.axes_manager.signal_shape)
if not isinstance(nav_chunks, tuple):
nav_chunks = (nav_chunks,) * len(self.axes_manager.navigation_shape)
if self.ragged and len(self.axes_manager.navigation_shape) == 0:
nav_chunks = (nav_chunks,) * 1
else:
nav_chunks = (nav_chunks,) * len(self.axes_manager.navigation_shape)
new_chunks = nav_chunks + sig_chunks
if inplace:
self.data = self.data.rechunk(new_chunks, **kwargs)
Expand Down
13 changes: 13 additions & 0 deletions hyperspy/tests/signals/test_ragged_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ def test_slicing(self):
with pytest.raises(RuntimeError):
s.isig[0]

def test_ragged_0D_map(self):
def return_value(val):
return val

zeroDragged = self.s.inav[0, 0]

new_signal = zeroDragged.map(return_value, inplace=False)
if self.s._lazy:
new_signal.compute()
assert self.s.data[0, 0].compute().shape == new_signal.data[0].shape
else:
self.s.data[0, 0].shape == new_signal.data[0].shape


def test_create_ragged_array():
data = np.array([[0, 1], [2, 3, 4]], dtype=object)
Expand Down

0 comments on commit f0aac04

Please sign in to comment.