FIX _get_items_to_delete raising error when items list empty#1503
FIX _get_items_to_delete raising error when items list empty#1503tomMoral merged 7 commits intojoblib:masterfrom
_get_items_to_delete raising error when items list empty#1503Conversation
when calling `.reduce_size` on a newly created memory object without any cached items, it raises a `ValueError: min() arg is an empty sequence`. The argument of `age_limit` must not be None for this case. Fixed by providing a default value to the `min` function used in calculating the oldest item, which would be the current datetime as no items exist.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1503 +/- ##
==========================================
- Coverage 94.99% 94.95% -0.04%
==========================================
Files 45 45
Lines 7551 7556 +5
==========================================
+ Hits 7173 7175 +2
- Misses 378 381 +3
☔ View full report in Codecov by Sentry. |
tomMoral
left a comment
There was a problem hiding this comment.
thanks a lot for the pr.!
maybe a simpler solution is to skip the function of no item is present?
also could you add a non regression test for this case?
|
Thank you for your comment! 🚀
I would certainly like to try it. Full disclosure: |
|
A non-regression test is a test case in I agree that the simpler is to skip the function when the |
- return on empty items list
test__get_items_to_delete() function
|
There's a test that failed on last merge on main related to reduce size and age limit on windows: https://dev.azure.com/joblib/joblib/_build/results?buildId=3725&view=logs&j=8008bb8c-6b4f-56d5-66f4-b1d037aba1bf&t=7af8808d-3494-56e0-c1dc-6fbf5bb2bc40&l=1563 Could it be related to those changes ? (edit: doesn't seem likely) |
|
Can we please get this sorted out and merged? It's a pain running with the following construct: from datetime import timedelta
from joblib import Memory
cache_dir: Memory = Memory("/tmp/") # nosec
try:
cache_dir.reduce_size(age_limit=timedelta(days=1))
except ValueError:
# https://github.com/joblib/joblib/pull/1503
@cache_dir.cache(verbose=0)
def dummy():
"""Define dummy function to initialize the cache."""
dummy()
cache_dir.reduce_size(age_limit=timedelta(days=1))
# define cached functions |
when calling
.reduce_sizeon a newly created memory object without any cached items, it raises aValueError: min() arg is an empty sequence. The argument ofage_limitmust not be None for this case.Fixed by providing a default value to the
minfunction used in calculating the oldest item, which would be the current datetime as no items exist.