Merged
Conversation
simsta87
reviewed
Apr 10, 2026
simsta87
approved these changes
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
The previous flagging system requires all flag values to be powers of two, enabling bitwise combination of multiple flags on a single column. This design suits our FDRI workflows where multiple flag conditions can co-exist on a single observation.
However, many users come with existing flagging schemes that do not follow this convention - for example, legacy datasets using codes like
{good: 0, bad: 1, suspect: 2}or string codes like{good: "G", bad: "B", suspect: "S"}. These don't follow the bitwise integer pattern. There will be some categorical schemes that need to be considered mutually exclusive - row holds exactly one flag value, not a combination. There will be others that can have combinations, but obviously won't be able to use the bitwise combination, so instead will need appending into a list of flag values.This PR implements a categorical flag system as an alternative to the existing bitwise system.
Main changes
Categorical flag system
CategoricalFlagsupports arbitrary int or str flag values with no power-of-two constraint. Columns operate in either scalar mode (one value per row) or list mode (multiple values per row. Validation is done to ensure that duplicate values are rejected.CategoricalFlagColumnis introduced that defines how flags are added/removed via theadd_flagandremove_flagmethods on the base TimeFrame class.add_flagsets the value where the expression is true (with anoverwriteoption to control whether existing values are replaced);remove_flagsets the value to null.add_flagappends the value to the list (if it doesn't already exist);remove_flagremoves it from the list.flags/directoryflag_system.py- FlagSystemBase (mixin defining the shared interface: system_name, to_dict, get_flag, value_type, validate_column) and FlagMeta (shared metaclass base providing repr, eq, and hash on theclass itself rather than its instances).
bitwise_flag_system.py-BitwiseFlag, now inheriting fromFlagSystemBaseandBitwiseMeta.categorical_flag_system.py-CategoricalFlag, inheriting fromFlagSystemBaseandCategoricalMeta.flag_manager.py- updated FlagManager registry supporting both system types, withFlagColumnpromoted to an abstract base class.BitwiseFlagColumnandCategoricalFlagColumnare concrete subclasses implementing theappropriate add_flag, remove_flag, encode, and decode semantics.
Other changes
_configure_period_properties()method split into individual @staticmethod methods (_configure_resolution_property,_configure_offset_property,_configure_alignment_property,_configure_periodicity_property)is_inoperator now wraps a scalar compare_to value in a list, fixing a case where a non-list value was passed directly topl.Expr.is_in.get_date_columns(calculations.py): added explicit return None at the end of the function to satisfy type checkers.Note
Files under src/time_stream/flags/ and tests/time_stream/flags/ will appear as new files in the diff rather than renames, because the content changed significantly during the move. The old bitwise.py and flag_manager.py at the top-level time_stream/ package have been deleted. Sorry this makes the git diff difficult to follow...
Usage examples
Categorical flag system - integer values (scalar mode)
Categorical flag system - string values (scalar mode)
List mode - multiple flags per row
Decode and encode