Skip to content

Commit

Permalink
Based on suggestion in numpy issue, updating to directly subclass uin…
Browse files Browse the repository at this point in the history
…t32 rather than python int

numpy/numpy#27540 (comment)
  • Loading branch information
WilliamJamieson committed Oct 30, 2024
1 parent 99446a3 commit 33e56a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/roman_datamodels/dqflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""
Expand Down
5 changes: 3 additions & 2 deletions tests/test_dqflags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from math import log10

import numpy as np
import pytest

from roman_datamodels import datamodels as rdm
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 33e56a7

Please sign in to comment.