Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX _get_items_to_delete raising error when items list empty #1503

Merged
merged 7 commits into from
Nov 11, 2023

Conversation

Dr-Blank
Copy link
Contributor

@Dr-Blank Dr-Blank commented Sep 6, 2023

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.

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
Copy link

codecov bot commented Sep 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (05caf07) 94.99% compared to head (4bfa65a) 94.95%.

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     
Files Coverage Δ
joblib/_store_backends.py 92.09% <100.00%> (-0.87%) ⬇️
joblib/test/test_memory.py 98.52% <100.00%> (+<0.01%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

joblib/_store_backends.py Outdated Show resolved Hide resolved
@Dr-Blank
Copy link
Contributor Author

Dr-Blank commented Sep 6, 2023

Thank you for your comment! 🚀

also could you add a non regression test for this case?

I would certainly like to try it.

Full disclosure:
I am a beginner programmer and would love to attempt this, however at the time of reading I do not understand what regression tests mean 😅

@tomMoral
Copy link
Contributor

tomMoral commented Sep 6, 2023

A non-regression test is a test case in test_memory.py, that checks that calling reduce_size on an empty memory object and verify that it does not crash.

I agree that the simpler is to skip the function when the items list is empty.

@Dr-Blank Dr-Blank marked this pull request as ready for review November 11, 2023 19:44
Copy link
Contributor

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thanks for the PR @Dr-Blank !

@tomMoral tomMoral merged commit 8e6ca75 into joblib:master Nov 11, 2023
16 checks passed
@Dr-Blank Dr-Blank deleted the fix-memory-reduce-size branch November 11, 2023 20:18
@fcharras
Copy link
Contributor

fcharras commented Nov 13, 2023

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)

@gothicVI
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants