fix: accept any os.PathLike in dump() and load(), not just pathlib.Path - #1812
Merged
Nanored4498 merged 4 commits intoJul 15, 2026
Merged
Conversation
dump() checked isinstance(filename, Path) before converting to str, so any path-like object that is not a pathlib.Path subclass (e.g. BIDSPath from mne-bids, or any custom os.PathLike) raised a ValueError even though load() already accepted it via open(). Replace both isinstance checks with os.PathLike so dump and load behave consistently for all path-like objects. Remove the now-unused pathlib.Path import. Adds test_dump_and_load_accept_os_pathlike to cover this path. fixes joblib#1784
Nanored4498
requested changes
Jul 6, 2026
Nanored4498
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the PR. Just few things before merging.
Contributor
There was a problem hiding this comment.
Could you reverse these changes that will be merged in your other PR #1811? :)
Contributor
There was a problem hiding this comment.
Suggested change
| filename: str, os.PathLike, or file object. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1812 +/- ##
==========================================
- Coverage 94.15% 94.10% -0.05%
==========================================
Files 46 46
Lines 7970 7979 +9
==========================================
+ Hits 7504 7509 +5
- Misses 466 470 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Done — reverted the logger.py docstrings so they only land in #1811, and applied the os.PathLike wording to both dump() and load(). PR is just the pathlike change + test now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1784.
dump()converted the filename to a string only whenisinstance(filename, pathlib.Path). Any other path-like object — such asBIDSPathfrom mne-bids, or any custom class implementing__fspath__— fell through to theis_filenamecheck, failed it, and raised:This was inconsistent with
load(), which passed non-Path path-likes straight toopen(), which accepts anyos.PathLike.Fix: Replace both
isinstance(filename, Path)guards withisinstance(filename, os.PathLike)and convert viaos.fspath(). This is the standard Python protocol for path-like objects. Remove the now-unusedfrom pathlib import Pathimport.What changed:
joblib/numpy_pickle.py— twoisinstance(filename, Path)→isinstance(filename, os.PathLike)withos.fspath(); removed unusedPathimportjoblib/test/test_numpy_pickle.py— addedtest_dump_and_load_accept_os_pathlikeusing a minimal customos.PathLikeclass (no external dependency needed)Both
test_pathlib(existing) and the new test pass.