Skip to content

Commit dcf83eb

Browse files
authored
[SWAT-734][Internal] Fixing conversion to darwin_json_1.0 (#523)
# Changelog Changed settings for Darwin JSON 1.0 importer to be tolerant of (invalid) non-string keys in JSON, as we have found some data with these. Root cause-analyses can follow.
1 parent 693340f commit dcf83eb

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

darwin/exporter/formats/darwin_1_0.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
from pathlib import Path
2-
from typing import Any, Dict, Iterable, List, Union
2+
from typing import Any, Dict, Iterable, Union
33

44
import orjson as json
55

66
import darwin.datatypes as dt
7-
from darwin.exporter.formats.numpy_encoder import NumpyEncoder
87

98

109
def export(annotation_files: Iterable[dt.AnnotationFile], output_dir: Path) -> None:
1110
for id, annotation_file in enumerate(annotation_files):
1211
_export_file(annotation_file, id, output_dir)
1312

1413

15-
def _export_file(annotation_file: dt.AnnotationFile, id: int, output_dir: Path):
14+
def _export_file(annotation_file: dt.AnnotationFile, id: int, output_dir: Path) -> None:
1615
output: Dict[str, Any] = _build_json(annotation_file)
1716
output_file_path: Path = (output_dir / annotation_file.filename).with_suffix(".json")
1817
with open(output_file_path, "w") as f:
19-
op = json.dumps(output, option=json.OPT_INDENT_2 | json.OPT_SERIALIZE_NUMPY).decode("utf-8")
18+
op = json.dumps(output, option=json.OPT_INDENT_2 | json.OPT_SERIALIZE_NUMPY | json.OPT_NON_STR_KEYS).decode(
19+
"utf-8"
20+
)
2021
f.write(op)
2122

2223

@@ -42,7 +43,7 @@ def _build_image_json(annotation_file: dt.AnnotationFile):
4243
**_build_metadata(annotation_file),
4344
},
4445
"annotations": list(map(_build_annotation, annotation_file.annotations)),
45-
"dataset": str(annotation_file.dataset_name)
46+
"dataset": str(annotation_file.dataset_name),
4647
}
4748

4849

@@ -63,7 +64,7 @@ def _build_video_json(annotation_file: dt.AnnotationFile):
6364
**_build_metadata(annotation_file),
6465
},
6566
"annotations": list(map(_build_annotation, annotation_file.annotations)),
66-
"dataset": str(annotation_file.dataset_name)
67+
"dataset": str(annotation_file.dataset_name),
6768
}
6869

6970

0 commit comments

Comments
 (0)