From e1fc0ecde8b57b08676f75bb8bfdb19ce47eb1fd Mon Sep 17 00:00:00 2001 From: Nick Smith Date: Mon, 9 Dec 2024 10:20:48 -0600 Subject: [PATCH] Migrate from defaultdict to Counter To fix: src/correctionlib/schemav2.py:419:37: B910 Use Counter() instead of defaultdict(int) to avoid excessive memory use --- src/correctionlib/schemav2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/correctionlib/schemav2.py b/src/correctionlib/schemav2.py index 5f760b9..2073359 100644 --- a/src/correctionlib/schemav2.py +++ b/src/correctionlib/schemav2.py @@ -1,6 +1,6 @@ import math import sys -from collections import defaultdict +from collections import Counter from typing import Dict, List, Optional, Set, Tuple, Union from pydantic import ( @@ -416,7 +416,7 @@ def validate_output(cls, output: Variable) -> Variable: return output def summary(self) -> Tuple[Dict[str, int], Dict[str, _SummaryInfo]]: - nodecount: Dict[str, int] = defaultdict(int) + nodecount: Dict[str, int] = Counter() inputstats = {var.name: _SummaryInfo() for var in self.inputs} if not isinstance(self.data, float): self.data.summarize(nodecount, inputstats)