From 509ea67fe32a4c3b7a6c13dd8eb20c77db42f095 Mon Sep 17 00:00:00 2001 From: Vibhu Jawa Date: Thu, 5 Sep 2024 16:53:38 -0600 Subject: [PATCH] Fix memory leak (#80) * Fix memory leak Signed-off-by: Vibhu Jawa * fix lru_cache * switch to cached property as we should not really cache the object --------- Signed-off-by: Vibhu Jawa --- crossfit/data/dataframe/core.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crossfit/data/dataframe/core.py b/crossfit/data/dataframe/core.py index 9ec969c7..341bffa0 100644 --- a/crossfit/data/dataframe/core.py +++ b/crossfit/data/dataframe/core.py @@ -14,7 +14,7 @@ from __future__ import annotations -from functools import lru_cache +from functools import cached_property from typing import Callable, List from crossfit.data.array.conversion import convert_array @@ -348,8 +348,8 @@ def _(data): # Fall-back `ArrayBundle` definition class ArrayBundle(FrameBackend): - @lru_cache - def __len__(self): + @cached_property + def _cached_len(self): _len = None for k, v in self.data.items(): if _len is None: @@ -358,6 +358,9 @@ def __len__(self): raise ValueError(f"Column {k} was length {len(v)}, but expected length {_len}") return _len + def __len__(self): + return self._cached_len + @property def dtypes(self) -> dict: # TODO: Does this work for "all" supported Array types? @@ -421,7 +424,7 @@ def assign(self, **kwargs): data = self.data.copy() for k, v in kwargs.items(): if self.columns and len(v) != len(self): - raise ValueError(f"Column {k} was length {len(v)}, but expected length {len(self)}") + raise ValueError(f"Column {k} was length {len(v)} but expected length {len(self)}") data.update(**kwargs) return self.__class__(data)