From 42be1b9fd5389b9ec79ba024b8e1ed2ac8417685 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Sun, 27 Sep 2026 04:36:19 -0700 Subject: [PATCH] Cast source sequence counter to int32 before gap arithmetic Signed-off-by: Sai Asish Y --- imap_processing/tests/test_utils.py | 13 +++++++++++++ imap_processing/utils.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/imap_processing/tests/test_utils.py b/imap_processing/tests/test_utils.py index 9e521c7b4..f1e5ded16 100644 --- a/imap_processing/tests/test_utils.py +++ b/imap_processing/tests/test_utils.py @@ -375,6 +375,19 @@ def test_check_source_sequence_counter(caplog): assert "Found [2] gap(s) in source sequence counter for APID 1234" in caplog.text +@pytest.mark.filterwarnings("error::RuntimeWarning") +def test_check_source_sequence_counter_unsigned_rollover(caplog): + """Test _check_source_sequence_counter with unsigned counters that roll over.""" + data_vars = { + "src_seq_ctr": (["epoch"], np.array([10221, 4933, 4934], dtype=np.uint16)), + } + ds = xr.Dataset(data_vars=data_vars) + + utils._check_source_sequence_counter(ds, apid=1188) + + assert "(11095 total missing packets)" in caplog.text + + def test_extract_data_dict(): """Test extract_data_dict function.""" data_vars = { diff --git a/imap_processing/utils.py b/imap_processing/utils.py index 9526dba46..72d76f8f4 100644 --- a/imap_processing/utils.py +++ b/imap_processing/utils.py @@ -456,7 +456,7 @@ def _check_source_sequence_counter(ds: xr.Dataset, apid: int) -> None: # Check for sequential source sequence counters # CCSDS source sequence counter is a 14-bit field (0-16383) counter_max = 16384 - src_seq_ctr = ds["src_seq_ctr"].data + src_seq_ctr = ds["src_seq_ctr"].data.astype(np.int32) if len(src_seq_ctr) <= 1: return