Skip to content

Commit 9f1b18a

Browse files
arnoegwtensorflower-gardener
authored andcommitted
Change internal constant RESERVED_REGEX to RESERVED_FEATURE_NAME_PATTERN.
The new name better reflects the meaning. The new type (plain str) is more appropriate as a constant and can be used in more places. PiperOrigin-RevId: 515460315
1 parent 5b6310f commit 9f1b18a

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

tensorflow_gnn/graph/graph_constants.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# ==============================================================================
1515
"""Constant strings used throughout the package."""
1616

17-
import re
1817
from typing import Any, List, Mapping, Optional, Sequence, Tuple, Union
1918

2019
import tensorflow as tf
@@ -36,16 +35,15 @@
3635
SOURCE_NAME = '#source'
3736
TARGET_NAME = '#target'
3837
RESERVED_FEATURES = frozenset({SIZE_NAME, SOURCE_NAME, TARGET_NAME})
38+
# The pattern of feature names (present and future) that are not allowed on a
39+
# graph tensor and schema, for use with re.fullmatch(pattern, feature_name).
40+
RESERVED_FEATURE_NAME_PATTERN = r'#.*'
3941

4042
# The conventional feature name for the hidden state (neuron activations) of
4143
# an edge set, a node set or the context. Not special in GraphTensor, but used
4244
# in some modeling libraries on top if explicit names are not needed.
4345
HIDDEN_STATE = 'hidden_state'
4446

45-
# The pattern of feature names that are not allowed on a graph tensor and
46-
# schema.
47-
RESERVED_REGEX = re.compile(r'#.*')
48-
4947
# The internal metadata key prefix to use for hyper adjacency.
5048
INDEX_KEY_PREFIX = '#index.'
5149

tensorflow_gnn/graph/schema_validation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# ==============================================================================
1515
"""Graph schema validation routines."""
1616

17+
import re
1718
from typing import List, Optional, Sequence
1819

1920
from absl import logging # TODO(blais): Remove, see below.
@@ -235,7 +236,7 @@ def _validate_schema_reserved_feature_names(schema: schema_pb2.GraphSchema):
235236
# TODO(blais): Make this compulsory after we remove the hardcoded
236237
# feature names from the sampler.
237238
for set_type, set_name, feature_name, feature in su.iter_features(schema):
238-
if const.RESERVED_REGEX.match(feature_name):
239+
if re.fullmatch(const.RESERVED_FEATURE_NAME_PATTERN, feature_name):
239240
logging.error("Invalid %s feature name '%s' on set '%s': reserved names "
240241
"are not allowed", set_type, feature_name, set_name)
241242

0 commit comments

Comments
 (0)