Skip to content

Commit

Permalink
fix(datastore): fix parsing type list to tuple (#2231)
Browse files Browse the repository at this point in the history
  • Loading branch information
jialeicui authored May 15, 2023
1 parent 9569686 commit 5293c80
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
5 changes: 4 additions & 1 deletion client/starwhale/api/_impl/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ def decode_schema_from_type_encoded_value(value: Dict[str, Any]) -> "SwType":
# TODO: support more than one item types
if isinstance(v, (list, tuple)) and len(v) != 0:
element_type = SwType.decode_schema_from_type_encoded_value(v[0])
return SwTupleType(element_type)
if type_name == "LIST":
return SwListType(element_type)
else:
return SwTupleType(element_type)
if type_name == "MAP":
# {
# "type": "MAP",
Expand Down
26 changes: 26 additions & 0 deletions client/tests/sdk/test_data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
STRING,
SwType,
SwMapType,
SwListType,
SwTupleType,
ColumnSchema,
TableWriterException,
)
Expand Down Expand Up @@ -2385,6 +2387,30 @@ def test_decode_schema_from_type_encoded_values():
decoded = schema.decode_from_type_encoded_value(value)
assert decoded == {1: "foobar"}

# list
value = {
"type": "LIST",
"value": [
{"type": "STRING", "value": "foobar"},
],
}
schema = SwType.decode_schema_from_type_encoded_value(value)
assert schema == SwListType(STRING)
decoded = schema.decode_from_type_encoded_value(value)
assert decoded == ["foobar"]

# tuple
value = {
"type": "TUPLE",
"value": [
{"type": "STRING", "value": "foobar"},
],
}
schema = SwType.decode_schema_from_type_encoded_value(value)
assert schema == SwTupleType(STRING)
decoded = schema.decode_from_type_encoded_value(value)
assert decoded == ("foobar",)


if __name__ == "__main__":
unittest.main()
4 changes: 1 addition & 3 deletions example/PennFudanPed/pfp/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ def make_coco_evaluator(ann_list, iou_types) -> CocoEvaluator:
"image_id": _a.image_id,
"category_id": _a.category_id,
"area": _a.area,
# FIXME: (workaround) convert tuple to list.
# in the server side, the bbox is changed to tuple type, but in the client side, it is list type.
"bbox": list(_a.bbox) if isinstance(_a.bbox, tuple) else _a.bbox,
"bbox": _a.bbox,
"iscrowd": _a.iscrowd,
"segmentation": _a.segmentation,
}
Expand Down

0 comments on commit 5293c80

Please sign in to comment.