Repository: joblib/joblib

Issue:
Silent failure if Path("...") is passed - BUG
The following code shows a silent failure when a Path is passed.

```
from pathlib import Path
from joblib import Memory

m1 = Memory(Path('../joblib-cache'), verbose=True)
m2 = Memory('../joblib-cache', verbose=True)

@m1.cache
def foo1(x):
    return x

@m2.cache
def foo2(x):
    return x

foo1(3)
foo2(3)
```

Printing only the verbose joblib output for foo2, and not caching foo1.

`python --version == 3.7 ; joblib.__version__ == 0.13.0`

May have time to produce a pull request tomorrow.

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/joblib/joblib/pull/817?src=pr&el=h1) Report
> Merging [#817](https://codecov.io/gh/joblib/joblib/pull/817?src=pr&el=desc) into [master](https://codecov.io/gh/joblib/joblib/commit/7be116a5a6bd4b304c1b0be66bc44fc84cfb0267?src=pr&el=desc) will **increase** coverage by `0.04%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/joblib/joblib/pull/817/graphs/tree.svg?width=650&token=gA6LF5DGTW&height=150&src=pr)](https://codecov.io/gh/joblib/joblib/pull/817?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master    #817      +/-   ##
=========================================
+ Coverage   95.35%   95.4%   +0.04%     
=========================================
  Files          44      44              
  Lines        6307    6328      +21     
=========================================
+ Hits         6014    6037      +23     
+ Misses        293     291       -2
```


| [Impacted Files](https://codecov.io/gh/joblib/joblib/pull/817?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [joblib/test/test\_memory.py](https://codecov.io/gh/joblib/joblib/pull/817/diff?src=pr&el=tree#diff-am9ibGliL3Rlc3QvdGVzdF9tZW1vcnkucHk=) | `98.15% <100%> (+0.04%)` | :arrow_up: |
| [joblib/memory.py](https://codecov.io/gh/joblib/joblib/pull/817/diff?src=pr&el=tree#diff-am9ibGliL21lbW9yeS5weQ==) | `95.69% <100%> (+0.08%)` | :arrow_up: |
| [joblib/test/test\_store\_backends.py](https://codecov.io/gh/joblib/joblib/pull/817/diff?src=pr&el=tree#diff-am9ibGliL3Rlc3QvdGVzdF9zdG9yZV9iYWNrZW5kcy5weQ==) | `91.17% <0%> (-5.89%)` | :arrow_down: |
| [joblib/\_parallel\_backends.py](https://codecov.io/gh/joblib/joblib/pull/817/diff?src=pr&el=tree#diff-am9ibGliL19wYXJhbGxlbF9iYWNrZW5kcy5weQ==) | `97.2% <0%> (+1.2%)` | :arrow_up: |
| [joblib/logger.py](https://codecov.io/gh/joblib/joblib/pull/817/diff?src=pr&el=tree#diff-am9ibGliL2xvZ2dlci5weQ==) | `88.15% <0%> (+1.31%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/joblib/joblib/pull/817?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/joblib/joblib/pull/817?src=pr&el=footer). Last update [7be116a...104ddab](https://codecov.io/gh/joblib/joblib/pull/817?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 4095118..63054fd 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,15 @@
 Latest changes
 ===============
 
+Release 0.13.1
+--------------
+
+Pierre Glaser
+
+   Memory now accepts pathlib.Path objects as ``location`` parameter.
+   Also, a warning is raised if the returned backend is None while
+   ``location`` is not None.
+
 Release 0.13.0
 --------------
 
diff --git a/joblib/memory.py b/joblib/memory.py
index f744aaa..a1c4ff6 100644
--- a/joblib/memory.py
+++ b/joblib/memory.py
@@ -18,6 +18,7 @@ import functools
 import traceback
 import warnings
 import inspect
+import sys
 import weakref
 
 # Local imports
@@ -30,6 +31,9 @@ from .logger import Logger, format_time, pformat
 from ._compat import _basestring, PY3_OR_LATER
 from ._store_backends import StoreBackendBase, FileSystemStoreBackend
 
+if sys.version_info[:2] >= (3, 4):
+    import pathlib
+
 
 FIRST_LINE_TEXT = "# first line:"
 
@@ -101,6 +105,9 @@ def _store_backend_factory(backend, location, verbose=0, backend_options=None):
     if backend_options is None:
         backend_options = {}
 
+    if (sys.version_info[:2] >= (3, 4) and isinstance(location, pathlib.Path)):
+        location = str(location)
+
     if isinstance(location, StoreBackendBase):
         return location
     elif isinstance(location, _basestring):
@@ -124,6 +131,12 @@ def _store_backend_factory(backend, location, verbose=0, backend_options=None):
         obj.configure(location, verbose=verbose,
                       backend_options=backend_options)
         return obj
+    elif location is not None:
+        warnings.warn(
+            "Instanciating a backend using a {} as a location is not "
+            "supported by joblib. Returning None instead.".format(
+                location.__class__.__name__), UserWarning)
+
 
     return None
 


Test patch:
diff --git a/joblib/test/test_memory.py b/joblib/test/test_memory.py
index 65f96dc..fb83725 100644
--- a/joblib/test/test_memory.py
+++ b/joblib/test/test_memory.py
@@ -31,6 +31,9 @@ from joblib.testing import parametrize, raises, warns
 from joblib._compat import PY3_OR_LATER
 from joblib.hashing import hash
 
+if sys.version_info[:2] >= (3, 4):
+    import pathlib
+
 
 ###############################################################################
 # Module-level variables for the tests
@@ -1043,6 +1046,20 @@ def test_memory_default_store_backend():
     excinfo.match(r"Unknown location*")
 
 
+def test_warning_on_unknown_location_type():
+    class NonSupportedLocationClass:
+        pass
+    unsupported_location = NonSupportedLocationClass()
+
+    with warns(UserWarning) as warninfo:
+        _store_backend_factory("local", location=unsupported_location)
+
+    expected_mesage = ("Instanciating a backend using a "
+                       "NonSupportedLocationClass as a location is not "
+                       "supported by joblib")
+    assert expected_mesage in str(warninfo[0].message)
+
+
 def test_instanciate_incomplete_store_backend():
     # Verify that registering an external incomplete store backend raises an
     # exception when one tries to instanciate it.
@@ -1066,6 +1083,15 @@ def test_dummy_store_backend():
     assert isinstance(backend_obj, DummyStoreBackend)
 
 
+@pytest.mark.skipif(sys.version_info[:2] < (3, 4),
+                    reason="pathlib is available for python versions >= 3.4")
+def test_instanciate_store_backend_with_pathlib_path():
+    # Instanciate a FileSystemStoreBackend using a pathlib.Path object
+    path = pathlib.Path("some_folder")
+    backend_obj = _store_backend_factory("local", path)
+    assert backend_obj.location == "some_folder"
+
+
 def test_filesystem_store_backend_repr(tmpdir):
     # Verify string representation of a filesystem store backend.