From e4118625916d4438c79d9a226e0a2e6f1e88c7f9 Mon Sep 17 00:00:00 2001 From: Yao You Date: Thu, 10 Oct 2024 08:12:18 -0500 Subject: [PATCH] use field to set default empty array (#390) --- CHANGELOG.md | 4 ++++ unstructured_inference/__version__.py | 2 +- unstructured_inference/inference/layoutelement.py | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4d9bda5..1c2b466c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.7.39 + +* fix: Correctly assign mutable default value to variable in `LayoutElements` class + ## 0.7.38 * fix: Correctly assign mutable default value to variable in `TextRegions` class diff --git a/unstructured_inference/__version__.py b/unstructured_inference/__version__.py index fc9a3245..52680926 100644 --- a/unstructured_inference/__version__.py +++ b/unstructured_inference/__version__.py @@ -1 +1 @@ -__version__ = "0.7.38" # pragma: no cover +__version__ = "0.7.39" # pragma: no cover diff --git a/unstructured_inference/inference/layoutelement.py b/unstructured_inference/inference/layoutelement.py index f0d905d7..9341ab2d 100644 --- a/unstructured_inference/inference/layoutelement.py +++ b/unstructured_inference/inference/layoutelement.py @@ -1,6 +1,6 @@ from __future__ import annotations -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import Any, Collection, Iterable, List, Optional import numpy as np @@ -30,8 +30,8 @@ @dataclass class LayoutElements(TextRegions): - element_probs: np.ndarray = np.array([]) - element_class_ids: np.ndarray = np.array([]) + element_probs: np.ndarray = field(default_factory=lambda: np.array([])) + element_class_ids: np.ndarray = field(default_factory=lambda: np.array([])) element_class_id_map: dict[int, str] | None = None def __post_init__(self):