Add sentinel field to NumericalAttribute#42
Open
copybara-service[bot] wants to merge 1 commit into
Open
Conversation
37ace23 to
5fc5291
Compare
Adds a configurable `sentinel` field to `NumericalAttribute` (defaults to `np.nan`) that controls the value assigned to out-of-domain entries during reverse discretization when `clip_to_range` is False. Previously, out-of-domain values were unconditionally mapped to `None` (scalar path) or `np.nan` (vectorized path). With this change, users can supply a custom sentinel value (e.g. `-1`) to keep integer dtype arrays instead of silently promoting to float. When `interval_handling='interval'`, sentinel must be a string; for other modes it must be numeric (int or float). The pipeline proto does not persist sentinel; it always uses the default NaN on deserialization. Changes: - `domain.NumericalAttribute`: new `sentinel` field (float|int|str) with NaN default, bidirectional type validation (string ↔ interval), and NaN-safe `__eq__`/`__hash__` - `transformations.py`: `reverse()` returns sentinel when clip_to_range=False - `vectorized_transformations.py`: `undiscretize()` uses configurable sentinel - `pydantic_api.py`: convert NaN→None at output layer for pydantic compat PiperOrigin-RevId: 935074118
5fc5291 to
64b7b56
Compare
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.
Add sentinel field to NumericalAttribute
Adds a configurable
sentinelfield toNumericalAttribute(defaultsto
np.nan) that controls the value assigned to out-of-domain entriesduring reverse discretization when
clip_to_rangeis False.Previously, out-of-domain values were unconditionally mapped to
None(scalar path) or
np.nan(vectorized path). With this change, userscan supply a custom sentinel value (e.g.
-1) to keep integer dtypearrays instead of silently promoting to float. When
interval_handling='interval', sentinel must be a string; for othermodes it must be numeric (int or float).
The pipeline proto does not persist sentinel; it always uses the
default NaN on deserialization.
Changes:
domain.NumericalAttribute: newsentinelfield (float|int|str)with NaN default, bidirectional type validation (string ↔ interval),
and NaN-safe
__eq__/__hash__transformations.py:reverse()returns sentinel when clip_to_range=Falsevectorized_transformations.py:undiscretize()uses configurable sentinelpydantic_api.py: convert NaN→None at output layer for pydantic compat