Skip to content

Commit

Permalink
MAINT: Renaming update_cache to force_eval.
Browse files Browse the repository at this point in the history
Also, changing LoadFileMixin `cache_dataset` to be False by default, and checking as part of the cache retrieval whether it is False or not.
  • Loading branch information
mpu-creare committed Apr 17, 2020
1 parent c117b67 commit 6321511
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
14 changes: 7 additions & 7 deletions podpac/core/algorithm/test/test_stats.py
Expand Up @@ -278,15 +278,15 @@ class TestDayOfYear(object):

class F(DayOfYearWindow):
cache_output = tl.Bool(False)
cache_update = tl.Bool(True)
force_eval = tl.Bool(True)

def function(self, data, output):
return len(data)


class FM(DayOfYearWindow):
cache_output = tl.Bool(False)
cache_update = tl.Bool(True)
force_eval = tl.Bool(True)

def function(self, data, output):
return np.mean(data)
Expand All @@ -302,7 +302,7 @@ def test_doy_window1(self):
)

node = Arange()
nodedoywindow = F(source=node, window=1, cache_output=False, cache_update=True)
nodedoywindow = F(source=node, window=1, cache_output=False, force_eval=True)
o = nodedoywindow.eval(coords)

np.testing.assert_array_equal(o, [2, 2, 1, 1, 2, 2])
Expand All @@ -316,7 +316,7 @@ def test_doy_window2(self):
)

node = Arange()
nodedoywindow = F(source=node, window=2, cache_output=False, cache_update=True)
nodedoywindow = F(source=node, window=2, cache_output=False, force_eval=True)
o = nodedoywindow.eval(coords)

np.testing.assert_array_equal(o, [6, 5, 3, 3, 5, 6])
Expand All @@ -330,11 +330,11 @@ def test_doy_window2_mean_rescale_float(self):
)

node = Arange()
nodedoywindow = FM(source=node, window=2, cache_output=False, cache_update=True)
nodedoywindow = FM(source=node, window=2, cache_output=False, force_eval=True)
o = nodedoywindow.eval(coords)

nodedoywindow_s = FM(
source=node, window=2, cache_output=False, cache_update=True, scale_float=[0, coords.size], rescale=True
source=node, window=2, cache_output=False, force_eval=True, scale_float=[0, coords.size], rescale=True
)
o_s = nodedoywindow_s.eval(coords)

Expand All @@ -359,7 +359,7 @@ def test_doy_window2_mean_rescale_max_min(self):
source=node,
window=2,
cache_output=False,
cache_update=True,
force_eval=True,
scale_max=node_max,
scale_min=node_min,
rescale=False,
Expand Down
6 changes: 3 additions & 3 deletions podpac/core/data/file_source.py
Expand Up @@ -75,10 +75,10 @@ class LoadFileMixin(S3Mixin):
Attributes
----------
cache_dataset : bool
Whether to cache the dataset after loading.
Default is False. Whether to cache the dataset after loading (as an optimization).
"""

cache_dataset = tl.Bool(True)
cache_dataset = tl.Bool(False)

@cached_property
def _dataset_caching_node(self):
Expand All @@ -88,7 +88,7 @@ def _dataset_caching_node(self):
@cached_property
def dataset(self):
# use the _dataset_caching_node "stub" here because the only node attr we care about is the source
if self._dataset_caching_node.has_cache(key="dataset"):
if self.cache_dataset and self._dataset_caching_node.has_cache(key="dataset"):
data = self._dataset_caching_node.get_cache(key="dataset")
with BytesIO(data) as f:
return self._open(BytesIO(data), cache=False)
Expand Down
9 changes: 5 additions & 4 deletions podpac/core/node.py
Expand Up @@ -97,8 +97,9 @@ class Node(tl.HasTraits):
(CACHE_NODE_OUTPUT_DEFAULT for general Nodes, and CACHE_DATASOURCE_OUTPUT_DEFAULT for DataSource nodes).
If True, outputs will be cached and retrieved from cache. If False, outputs will not be cached OR retrieved from cache (even if
they exist in cache).
cache_update: bool
Default is True. Should the node's cached output be updated from the source data?
force_eval: bool
Default is False. Should the node's cached output be updated from the source data? If True it ignores the cache
when computing outputs but puts results into the cache (thereby updating the cache)
cache_ctrl: :class:`podpac.core.cache.cache.CacheCtrl`
Class that controls caching. If not provided, uses default based on settings.
dtype : type
Expand Down Expand Up @@ -129,7 +130,7 @@ class Node(tl.HasTraits):

dtype = tl.Any(default_value=float)
cache_output = tl.Bool()
cache_update = tl.Bool(False)
force_eval = tl.Bool(False)
cache_ctrl = tl.Instance(CacheCtrl, allow_none=True)

# list of attribute names, used by __repr__ and __str__ to display minimal info about the node
Expand Down Expand Up @@ -972,7 +973,7 @@ def wrapper(self, coordinates, output=None):
key = cache_key
cache_coordinates = coordinates.transpose(*sorted(coordinates.dims)) # order agnostic caching

if not self.cache_update and self.cache_output and self.has_cache(key, cache_coordinates):
if not self.force_eval and self.cache_output and self.has_cache(key, cache_coordinates):
data = self.get_cache(key, cache_coordinates)
if output is not None:
order = [dim for dim in output.dims if dim not in data.dims] + list(data.dims)
Expand Down

0 comments on commit 6321511

Please sign in to comment.