Skip to content

Commit

Permalink
Merge pull request #2903 from CSSFrancis/BugFixMapNonArraySignals
Browse files Browse the repository at this point in the history
BugFix: Map Function With non array signals.
  • Loading branch information
ericpre committed Mar 16, 2022
2 parents 76038e3 + 8ef01ed commit 7069ee3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hyperspy/misc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,9 +1340,9 @@ def process_function_blockwise(data,
islice = np.s_[index]
iter_dict = {}
for key, a in zip(arg_keys, args):
arg_i = a[islice].squeeze()
# Some functions does not handle 0-dimension NumPy arrys
if arg_i.shape == ():
arg_i = np.squeeze(a[islice])
# Some functions do not handle 0-dimension NumPy arrays
if hasattr(arg_i, "shape") and arg_i.shape == ():
arg_i = arg_i[()]
iter_dict[key] = arg_i
output_array[islice] = function(data[islice], **iter_dict, **kwargs)
Expand Down
9 changes: 9 additions & 0 deletions hyperspy/tests/signals/test_map_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,15 @@ def test_cropping_iterating_kwarg(self):
assert np.all(np.squeeze(arg.chunks[nav_dim:]) == arg.shape[nav_dim:])
assert np.all(s_iter0.data == np.squeeze(arg.compute()))

def test_iterating_kwarg_non_array(self):
def apply_func(data, f):
return f(data, data)
s = self.s.inav[0:2, 0:2]
iter_add = hs.signals.BaseSignal([[np.add, np.add],
[np.add, np.add]]).T
out = s.map(apply_func, f=iter_add, inplace=False)
np.testing.assert_array_equal(out.data, s.data)


class TestGetBlockPattern:
@pytest.mark.parametrize(
Expand Down
1 change: 1 addition & 0 deletions upcoming_changes/2903.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where the :py:func:`~.signal.BaseSignal.map` function wasn't operating properly when an iterating signal was not an array.

0 comments on commit 7069ee3

Please sign in to comment.