From 0730b779fc9713d2deff66e1685d84e3f8530c60 Mon Sep 17 00:00:00 2001 From: Malte Ziebarth Date: Mon, 13 Sep 2021 12:00:29 +0200 Subject: [PATCH] Handle new naming scheme in newer Jupyter notebook (#1214) Co-authored-by: Olivier Grisel --- CHANGES.rst | 4 ++++ joblib/func_inspect.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index c1e8c5290..a42c798a9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,10 @@ Development version is a decorated function. https://github.com/joblib/joblib/pull/1165 +- Fix `joblib.Memory` to properly handle caching for functions defined + interactively in a IPython session or in Jupyter notebook cell. + https://github.com/joblib/joblib/pull/1214 + 1.0.1 ----- diff --git a/joblib/func_inspect.py b/joblib/func_inspect.py index 37513478a..d334a2b9d 100644 --- a/joblib/func_inspect.py +++ b/joblib/func_inspect.py @@ -142,6 +142,13 @@ def get_func_name(func, resolv_alias=True, win_characters=True): # notebooks splitted = parts[-1].split('-') parts[-1] = '-'.join(splitted[:2] + splitted[3:]) + elif len(parts) > 2 and parts[-2].startswith('ipykernel_'): + # In a notebook session (ipykernel). Filename seems to be 'xyz' + # of above. parts[-2] has the structure ipykernel_XXXXXX where + # XXXXXX is a six-digit number identifying the current run (?). + # If we split it off, the function again has the same + # identifier across runs. + parts[-2] = 'ipykernel' filename = '-'.join(parts) if filename.endswith('.py'): filename = filename[:-3]