Skip to content

Commit 47e3576

Browse files
Uppercase subset enums (#1926)
<!-- Contributing guide: https://github.com/open-edge-platform/datumaro/blob/develop/contributing.md --> <!-- Please add a summary of changes. You may use Copilot to auto-generate the PR description but please consider including any other relevant facts which Copilot may be unaware of (such as design choices and testing procedure). Add references to the relevant issues and pull requests if any like so: Resolves #111 and #222. Depends on #1000 (for series of dependent commits). --> ### Checklist <!-- Put an 'x' in all the boxes that apply --> - [ ] I have added tests to cover my changes or documented any manual tests. - [ ] I have updated the [documentation](https://github.com/open-edge-platform/datumaro/tree/develop/docs) accordingly --------- Signed-off-by: Albert van Houten <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent c088924 commit 47e3576

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/datumaro/experimental/fields.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
class Subset(Enum):
2525
"""Standard dataset subset values."""
2626

27-
Training = auto()
28-
Validation = auto()
29-
Testing = auto()
27+
TRAINING = auto()
28+
VALIDATION = auto()
29+
TESTING = auto()
3030

3131

3232
T = TypeVar("T")

src/datumaro/experimental/legacy.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,17 +1533,25 @@ class SubsetConverter(ForwardAnnotationConverter):
15331533
Subset enum values while preserving unrecognized values as strings.
15341534
15351535
The following mappings are supported:
1536-
- Train: "train", "TRAINING" -> Subset.Training
1537-
- Validation: "val", "VALIDATION" -> Subset.Validation
1538-
- Test: "test", "TEST" -> Subset.Testing
1536+
- TRAINING: "train", "training" -> Subset.TRAINING
1537+
- VALIDATION: "val", "validation" -> Subset.VALIDATION
1538+
- TESTING: "test", "testing" -> Subset.TESTING
15391539
"""
15401540

1541-
# Combined lookup table mapping strings to enum values
1542-
_SUBSET_MAP = (
1543-
{name: Subset.Training for name in {"train", "TRAINING"}}
1544-
| {name: Subset.Validation for name in {"val", "VALIDATION"}}
1545-
| {name: Subset.Testing for name in {"test", "TEST"}}
1546-
)
1541+
# Case-insensitive + synonym lookup table mapping strings to enum values
1542+
_BASE_SUBSET_SYNONYMS = {
1543+
"train": Subset.TRAINING,
1544+
"training": Subset.TRAINING,
1545+
"val": Subset.VALIDATION,
1546+
"validation": Subset.VALIDATION,
1547+
"test": Subset.TESTING,
1548+
"testing": Subset.TESTING,
1549+
}
1550+
1551+
_SUBSET_MAP: dict[str, Subset] = {}
1552+
for key, value in _BASE_SUBSET_SYNONYMS.items():
1553+
for variant in {key, key.upper(), key.capitalize()}:
1554+
_SUBSET_MAP[variant] = value
15471555

15481556
def __init__(self, semantic: Semantic = Semantic.Default, name_prefix: str = ""):
15491557
"""Initialize the converter.

0 commit comments

Comments
 (0)