diff --git a/changes/402.misc.rst b/changes/402.misc.rst new file mode 100644 index 00000000..fd7ce683 --- /dev/null +++ b/changes/402.misc.rst @@ -0,0 +1,2 @@ +Use multiclass of `np.uint32` and `Enum` rather than a subclass of `IntEnum` for +the dqflags as suggested by the numpy devs. 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