From 6b53cc19b82ba4cb2ed0e56ce560aac99abb170a Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Tue, 15 Oct 2024 14:27:54 -0400 Subject: [PATCH] Based on suggestion in numpy issue, updating to directly subclass uint32 rather than python int https://github.com/numpy/numpy/issues/27540#issuecomment-2407652393 --- src/roman_datamodels/dqflags.py | 8 +++++--- tests/test_dqflags.py | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/roman_datamodels/dqflags.py b/src/roman_datamodels/dqflags.py index a0db85f6..c6331be7 100644 --- a/src/roman_datamodels/dqflags.py +++ b/src/roman_datamodels/dqflags.py @@ -19,12 +19,14 @@ the formula `2**bit_number` where `bit_number` is the 0-index bit of interest. """ -from enum import IntEnum, unique +from enum import Enum, unique + +import numpy as np # fmt: off @unique -class pixel(IntEnum): +class pixel(np.uint32, Enum): """Pixel-specific data quality flags""" GOOD = 0 # No bits set, all is good @@ -62,7 +64,7 @@ class pixel(IntEnum): @unique -class group(IntEnum): +class group(np.uint32, Enum): """Group-specific data quality flags Once groups are combined, these flags are equivalent to the pixel-specific flags. """ diff --git a/tests/test_dqflags.py b/tests/test_dqflags.py index 0b366543..27694a0a 100644 --- a/tests/test_dqflags.py +++ b/tests/test_dqflags.py @@ -1,5 +1,6 @@ from math import log10 +import numpy as np import pytest from roman_datamodels import datamodels as rdm @@ -30,7 +31,7 @@ def test_pixel_flags(flag): assert isinstance(flag, dqflags.pixel) # Test that the pixel flags are ints - assert isinstance(flag, int) + assert isinstance(flag, np.uint32) # Test that the pixel flags are dict accessible assert dqflags.pixel[flag.name] is flag @@ -78,7 +79,7 @@ def test_group_flags(flag): assert isinstance(flag, dqflags.group) # Test that the group flags are ints - assert isinstance(flag, int) + assert isinstance(flag, np.uint32) # Test that the group flags are dict accessible assert dqflags.group[flag.name] is flag