From 98bfa4bf3de6ffb75f338254d11ee4459ff93016 Mon Sep 17 00:00:00 2001 From: Tucker Alban Date: Wed, 1 Nov 2023 15:48:24 -0400 Subject: [PATCH] Fix lambda cannot be serialized. (#2102) * Fix issue where a lambda cannot be serialized. * Update changelog. * Make format. --- CHANGELOG.md | 1 + envision/data_formatter.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25aabc7812..8720e3399f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Copy and pasting the git commit messages is __NOT__ enough. ### Fixed - Fixed issue where `SumoTrafficSimulation` could get locked up on reset if a scenario had only 1 map but multiple scenario variations. - Fixed an issue where an out-of-scope method reference caused a pickling error. +- Fixed an issue where the `EnvisionDataFormatterArgs` default would use a locally defined lambda and cause a serialization failure. ### Removed ### Security diff --git a/envision/data_formatter.py b/envision/data_formatter.py index 1a0dae4e36..3e8a124bac 100644 --- a/envision/data_formatter.py +++ b/envision/data_formatter.py @@ -75,6 +75,10 @@ class Operation(IntEnum): _primitives = {int, float, str, VehicleType, TrafficActorType} +def _passthrough_method_1_arg(v): + return v + + class ReductionContext: """Mappings between an object and its reduction to an ID.""" @@ -126,7 +130,7 @@ class EnvisionDataFormatterArgs(NamedTuple): """Data formatter configurations.""" id: Optional[str] - serializer: Callable[[list], Any] = lambda d: d + serializer: Callable[[list], Any] = _passthrough_method_1_arg float_decimals: int = 2 bool_as_int: bool = True enable_reduction: bool = True