Skip to content

Commit 723c63a

Browse files
committed
Added warning to clear before save
1 parent e7d9b2b commit 723c63a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

stumpy/cache.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
CACHE_WARNING += "and should never be used or depended upon as it is not supported! "
1616
CACHE_WARNING += "All caching capabilities are not tested and may be removed/changed "
1717
CACHE_WARNING += "without prior notice. Please proceed with caution!"
18+
CACHE_CLEARED = True
1819

1920

2021
def get_njit_funcs():
@@ -115,6 +116,8 @@ def _clear(cache_dir=None):
115116
-------
116117
None
117118
"""
119+
global CACHE_CLEARED
120+
118121
if cache_dir is not None: # pragma: no cover
119122
numba_cache_dir = str(cache_dir)
120123
else: # pragma: no cover
@@ -123,6 +126,8 @@ def _clear(cache_dir=None):
123126

124127
[f.unlink() for f in pathlib.Path(numba_cache_dir).glob("*nb*") if f.is_file()]
125128

129+
CACHE_CLEARED = True
130+
126131

127132
def clear(cache_dir=None):
128133
"""
@@ -240,6 +245,8 @@ def save():
240245
The cache is never cleared before saving/overwriting and may be explicitly
241246
cleared by calling `cache.clear()` before saving.
242247
"""
248+
global CACHE_CLEARED
249+
243250
if numba.config.DISABLE_JIT:
244251
msg = "Could not save/cache function because NUMBA JIT is disabled"
245252
warnings.warn(msg)
@@ -251,6 +258,11 @@ def save():
251258
msg += "The `stumpy` cache files may not be saved/cleared correctly!"
252259
warnings.warn(msg)
253260

261+
if not CACHE_CLEARED: # pragma: no cover
262+
msg = "The cached files are not cleared before saving/overwriting. "
263+
msg = "You may need to call `cache.clear()` before calling `cache.save()`."
264+
warnings.warn("msg")
265+
254266
_save()
255267

256268
return

0 commit comments

Comments
 (0)