Skip to content

Commit

Permalink
Fix memory leak (#80)
Browse files Browse the repository at this point in the history
* Fix memory leak

Signed-off-by: Vibhu Jawa <[email protected]>

* fix lru_cache

* switch to cached property as we should not really cache the object

---------

Signed-off-by: Vibhu Jawa <[email protected]>
  • Loading branch information
VibhuJawa authored Sep 5, 2024
1 parent 9e52a90 commit 509ea67
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crossfit/data/dataframe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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?
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 509ea67

Please sign in to comment.