From 2acd2d03f0f922cb4cfdd04f171ee43ec198e46e Mon Sep 17 00:00:00 2001 From: Nicholas Smith Date: Fri, 10 Jan 2025 15:01:07 -0600 Subject: [PATCH] Migrate from defaultdict to Counter (#267) 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)