-
Notifications
You must be signed in to change notification settings - Fork 4
fix: abstract away category indexing differences #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """Compatibility helpers that abstract away differences between T4Dataset revisions.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from t4_devkit.schema import Category | ||
|
|
||
|
|
||
| def fix_category_table(categories: list[Category]) -> list[Category]: | ||
| """Fix unpopulated index fields in some T4Dataset revisions. | ||
|
|
||
| This function behaves differently in the below three cases: | ||
|
|
||
| - All `index` fields are set: the list is returned unmodified. | ||
| - All `index` fields are `None`: the position of each category in the list is used to compute | ||
| `index`. The resulting indices start at `0`. | ||
| - Some `index` fields are set and some are `None`: raise a `ValueError`. | ||
|
|
||
| Args: | ||
| categories (list[Category]): List of categories to fix. | ||
|
|
||
| Returns: | ||
| list[Category]: Fixed list of categories. | ||
|
|
||
| Raises: | ||
| ValueError: If the `index` field is set for some categories and `None` for others. | ||
| """ | ||
| if any(category.index is None for category in categories): | ||
| if not all(category.index is None for category in categories): | ||
| raise ValueError("Category index is not set for some categories.") | ||
|
|
||
| for idx, category in enumerate(categories): | ||
| category.index = idx | ||
|
Comment on lines
+31
to
+32
|
||
| return categories | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |||||
| from t4_devkit.dataclass import Box2D, Box3D, SemanticLabel, Shape, ShapeType | ||||||
| from t4_devkit.helper import RenderingHelper, TimeseriesHelper | ||||||
| from t4_devkit.schema import SchemaName, SensorModality, VisibilityLevel, build_schema | ||||||
| from t4_devkit.schema.compatibility import fix_category_table | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
| from t4_devkit.typing import CameraIntrinsicLike, Vector3 | ||||||
|
|
@@ -181,6 +182,8 @@ def __init__( | |||||
| self.annotation_dir, SchemaName.CALIBRATED_SENSOR | ||||||
| ) | ||||||
| self.category: list[Category] = load_table(self.annotation_dir, SchemaName.CATEGORY) | ||||||
| self.category = fix_category_table(self.category) | ||||||
|
||||||
| self.category = fix_category_table(self.category) | |
| fix_category_table(self.category) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is generic and doesn't help users diagnose which categories have missing indices. Consider including details about which categories are affected, such as 'Category index is not set for some categories: [list of category names or positions]'.