From 7ce8ed55e1693cb40571e30347f128e8bbf46692 Mon Sep 17 00:00:00 2001 From: Roman Shapovalov Date: Tue, 28 Jun 2022 16:11:49 -0700 Subject: [PATCH] Fix: typo in dict processing Summary: David had his code crashed when using frame_annot["meta"] dictionary. Turns out we had a typo. The tests were passing by chance since all the keys were single-character strings. Reviewed By: bottler Differential Revision: D37503987 fbshipit-source-id: c12b0df21116cfbbc4675a0182b9b9e6d62bad2e --- pytorch3d/implicitron/dataset/types.py | 2 +- tests/implicitron/test_types.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pytorch3d/implicitron/dataset/types.py b/pytorch3d/implicitron/dataset/types.py index 497b91ee..b8227567 100644 --- a/pytorch3d/implicitron/dataset/types.py +++ b/pytorch3d/implicitron/dataset/types.py @@ -226,7 +226,7 @@ def _dataclass_list_from_dict_list(dlist, typeannot): keys = np.split(list(all_keys_res), indices[:-1]) vals = np.split(list(all_vals_res), indices[:-1]) - return [cls(zip(*k, v)) for k, v in zip(keys, vals)] + return [cls(zip(k, v)) for k, v in zip(keys, vals)] elif not dataclasses.is_dataclass(typeannot): return dlist diff --git a/tests/implicitron/test_types.py b/tests/implicitron/test_types.py index 56352b93..aff749be 100644 --- a/tests/implicitron/test_types.py +++ b/tests/implicitron/test_types.py @@ -73,8 +73,8 @@ class TestDatasetTypes(unittest.TestCase): ) # dict - parsed = types._dataclass_from_dict({"k": dct}, Dict[str, FrameAnnotation]) - self.assertEqual(parsed, {"k": self.entry}) + parsed = types._dataclass_from_dict({"key": dct}, Dict[str, FrameAnnotation]) + self.assertEqual(parsed, {"key": self.entry}) def test_parsing_vectorized(self): dct = dataclasses.asdict(self.entry) @@ -83,10 +83,10 @@ class TestDatasetTypes(unittest.TestCase): self._compare_with_scalar(_NT(dct), _NT) self._compare_with_scalar((dct,), Tuple[FrameAnnotation]) self._compare_with_scalar([dct], List[FrameAnnotation]) - self._compare_with_scalar({"k": dct}, Dict[str, FrameAnnotation]) + self._compare_with_scalar({"key": dct}, Dict[str, FrameAnnotation]) dct2 = dct.copy() - dct2["meta"] = {"d": 76} + dct2["meta"] = {"aux": 76} self._compare_with_scalar(dct2, FrameAnnotation) def _compare_with_scalar(self, obj, typeannot, repeat=3):