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)