Skip to content

FIX Memory accepts any os.PathLike location - #1945

Merged
Nanored4498 merged 2 commits into
joblib:mainfrom
shashank11yadav:fix/memory-os-pathlike
Nov 12, 2026
Merged

Nanored4498 merged 2 commits into
joblib:mainfrom
shashank11yadav:fix/memory-os-pathlike

Conversation

@shashank11yadav

Copy link
Copy Markdown
Contributor

Fixes #1944

Memory converted only pathlib.Path locations to str. Any other os.PathLike object was rejected with a "not supported" warning, and caching was silently disabled, so cached functions ran again on every call.

This change converts every os.PathLike with os.fspath, the same way joblib.dump and joblib.load already do. pathlib.Path is an os.PathLike, so its behaviour does not change. Other path-like objects now get the same location handling as Path: no joblib subdirectory is added. The str checks in Memory.__init__ and Memory.cache are unchanged.

Changes:

  • joblib/memory.py: convert os.PathLike with os.fspath in _store_backend_factory, remove the now-unused pathlib import, and update the location docstring.
  • joblib/test/test_memory.py: add a module-level _CustomPathLike test class and include it in the two existing location_type parametrizations.
  • CHANGES.rst: new entry under "In Development".

Related: #960 (PathLike support in dump/load, already handled in #1812) and #1684 (str vs Path subdirectory behaviour, not changed here).

Testing:

  • pytest joblib/test/test_memory.py -k "not test_parallel_call_cached_function_defined_in_jupyter" --timeout 30 -vl: pass. test_parallel_call_cached_function_defined_in_jupyter (both parametrizations) was deselected: it fails on main in my test environment too.
  • pytest joblib/test/test_memory.py -k "preserves_location or preserves_cache_hits" --timeout 30 -vl: pass. The added _CustomPathLike cases fail without the fix.
  • ruff check and ruff format --check on joblib/memory.py and joblib/test/test_memory.py: pass.
  • pre-commit run --all-files (CI linting job) was not run locally.

Memory only converted pathlib.Path locations to str. Any other
os.PathLike object was rejected with a "not supported" warning and
caching was silently disabled. Convert every os.PathLike with
os.fspath, as dump and load already do.
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.55%. Comparing base (1e49a29) to head (e502eb7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1945      +/-   ##
==========================================
- Coverage   93.59%   93.55%   -0.04%     
==========================================
  Files          46       46              
  Lines        8690     8694       +4     
==========================================
+ Hits         8133     8134       +1     
- Misses        557      560       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Nanored4498

Copy link
Copy Markdown
Contributor

LGTM. Thanks for the PR.

@Nanored4498
Nanored4498 merged commit 68d64f0 into joblib:main Nov 12, 2026
33 of 34 checks passed
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.

Memory(location=...) disables caching for os.PathLike objects that are not pathlib.Path

2 participants