From ab1a21a0daea9dd734dea39627e7267d2a607d8e Mon Sep 17 00:00:00 2001 From: rstiskalek Date: Sat, 21 Oct 2023 11:43:52 +0100 Subject: [PATCH] Cache only filtered data --- csiborgtools/read/halo_cat.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/csiborgtools/read/halo_cat.py b/csiborgtools/read/halo_cat.py index 7602bdd..6992408 100644 --- a/csiborgtools/read/halo_cat.py +++ b/csiborgtools/read/halo_cat.py @@ -455,12 +455,8 @@ class BaseCatalogue(ABC): else: is_internal = False - if key in self.cache_keys(): - out = self._cache[key] - if self._load_filtered and not is_internal: - return out[self._filter_mask] - else: - return out + if not is_internal and key in self.cache_keys(): + return self._cache[key] else: if key == "cartesian_pos": out = numpy.vstack([self["__x"], self["__y"], self["__z"]]).T @@ -501,16 +497,16 @@ class BaseCatalogue(ABC): else: raise KeyError(f"Key '{key}' is not available.") + if self._load_filtered and not is_internal: + out = out[self._filter_mask] + if not is_internal: self._cache[key] = out if self.cache_length() > self.cache_maxsize: self._cache.popitem(last=False) - if self._load_filtered and not is_internal: - return out[self._filter_mask] - else: - return out + return out @property def is_closed(self):