Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak #80

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading