From f2af9c0f7beba3ab59a442a21af1027816092ad7 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 31 Jul 2024 15:54:23 -0500 Subject: [PATCH] MNT #1260 refactor per discussion --- ophyd/tests/test_utils.py | 6 +++--- ophyd/utils/epics_pvs.py | 24 +++++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ophyd/tests/test_utils.py b/ophyd/tests/test_utils.py index 3af8a7ace..b8377e746 100644 --- a/ophyd/tests/test_utils.py +++ b/ophyd/tests/test_utils.py @@ -150,13 +150,13 @@ def test_set_signal_to_None(): # compare array shapes [[1, 2, 3], [1, 2, 3], [], None, None, True], # identical [[1, 2, 3], [0, 0, 0], [], None, None, False], # b has different values - [[1, 2, 3], [1, 2, 3, 0], [], None, None, True], # only compares len(a) items - [[1, 2, 3, 0], [1, 2, 3], [], None, None, False], # len(a) > len(b) + [[1, 2, 3], [1, 2, 3, 0], [], None, None, False], # different shape + # [[1, 2, 3, 0], [1, 2, 3], [], None, None, False], # len(a) > len(b) [5, [1, 2, 3], [], None, None, False], # not the same type [[1, 2, 3], 5, [], None, None, False], # not the same type # numpy arrays [[1, 2, 3], np.array([1, 2, 3]), [], None, None, True], # identical - [[1, 2, 3], np.array([1, 2, 3, 0]), [], None, None, True], # len(a) + # [[1, 2, 3], np.array([1, 2, 3, 0]), [], None, None, True], # len(a) # tuple [(1, 2, 3), np.array([1, 2, 3]), [], None, None, True], # identical # with tolerance diff --git a/ophyd/utils/epics_pvs.py b/ophyd/utils/epics_pvs.py index 3e8793721..a28a403aa 100644 --- a/ophyd/utils/epics_pvs.py +++ b/ophyd/utils/epics_pvs.py @@ -267,7 +267,9 @@ def _wait_for_value(signal, val, poll_time=0.01, timeout=10, rtol=None, atol=Non TimeoutError if timeout is exceeded """ expiration_time = ttime.time() + timeout if timeout is not None else None - current_value = signal.get() + array_like = (list, np.ndarray, tuple) + item_count = None if not isinstance(val, array_like) else len(val) + current_value = signal.get(count=item_count) if atol is None and hasattr(signal, "tolerance"): atol = signal.tolerance @@ -305,7 +307,7 @@ def _wait_for_value(signal, val, poll_time=0.01, timeout=10, rtol=None, atol=Non ttime.sleep(poll_time) if poll_time < 0.1: poll_time *= 2 # logarithmic back-off - current_value = signal.get() + current_value = signal.get(count=item_count) if expiration_time is not None and ttime.time() > expiration_time: raise TimeoutError( "Attempted to set %r to value %r and timed " @@ -335,15 +337,15 @@ def _compare_maybe_enum(a, b, enums, atol, rtol): # then compare the strings return a == b - array_like = (list, np.ndarray, tuple) - if isinstance(a, array_like) and isinstance(b, array_like): - a = np.array(a) # target - b = np.array(b) # reported by EPICS - if len(a.shape) == 1 and len(b.shape) == 1 and len(a) < len(b): - b = b[: len(a)] # cut 1-D EPICS array down to requested size - - if a.shape != b.shape: - return False + # array_like = (list, np.ndarray, tuple) + # if isinstance(a, array_like) and isinstance(b, array_like): + # a = np.array(a) # target + # b = np.array(b) # reported by EPICS + # if len(a.shape) == 1 and len(b.shape) == 1 and len(a) < len(b): + # b = b[: len(a)] # cut 1-D EPICS array down to requested size + + # if a.shape != b.shape: + # return False # if either relative/absolute tolerance is used, use numpy # to compare: