Skip to content

Commit 1e64b7b

Browse files
committed
Merge pull request #3212 from ogrisel/joblib-0.8.0
MAINT: joblib 0.8.0
2 parents 85bdeba + 181ffb8 commit 1e64b7b

17 files changed

Lines changed: 847 additions & 235 deletions

sklearn/externals/joblib/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
--------
2929
3030
The vision is to provide tools to easily achieve better performance and
31-
reproducibility when working with long running jobs. In addition, Joblib
32-
can also be used to provide a light-weight make replacement or caching
33-
solution.
31+
reproducibility when working with long running jobs.
3432
3533
* **Avoid computing twice the same thing**: code is rerun over an
3634
over, for instance when prototyping computational-heavy jobs (as in
@@ -102,10 +100,10 @@
102100
103101
"""
104102

105-
__version__ = '0.8.0a3'
103+
__version__ = '0.8.0'
106104

107105

108-
from .memory import Memory
106+
from .memory import Memory, MemorizedResult
109107
from .logger import PrintTime
110108
from .logger import Logger
111109
from .hashing import hash
File renamed without changes.

sklearn/externals/joblib/func_inspect.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414

1515
from ._compat import _basestring
16+
from .logger import pformat
1617

1718

1819
def get_func_code(func):
@@ -173,9 +174,7 @@ def filter_args(func, ignore_lst, args=(), kwargs=dict()):
173174
Returns
174175
-------
175176
filtered_args: list
176-
List of filtered positional arguments.
177-
filtered_kwdargs: dict
178-
List of filtered Keyword arguments.
177+
List of filtered positional and keyword arguments.
179178
"""
180179
args = list(args)
181180
if isinstance(ignore_lst, _basestring):
@@ -263,3 +262,41 @@ def filter_args(func, ignore_lst, args=(), kwargs=dict()):
263262
)))
264263
# XXX: Return a sorted list of pairs?
265264
return arg_dict
265+
266+
267+
def format_signature(func, *args, **kwargs):
268+
# XXX: Should this use inspect.formatargvalues/formatargspec?
269+
module, name = get_func_name(func)
270+
module = [m for m in module if m]
271+
if module:
272+
module.append(name)
273+
module_path = '.'.join(module)
274+
else:
275+
module_path = name
276+
arg_str = list()
277+
previous_length = 0
278+
for arg in args:
279+
arg = pformat(arg, indent=2)
280+
if len(arg) > 1500:
281+
arg = '%s...' % arg[:700]
282+
if previous_length > 80:
283+
arg = '\n%s' % arg
284+
previous_length = len(arg)
285+
arg_str.append(arg)
286+
arg_str.extend(['%s=%s' % (v, pformat(i)) for v, i in kwargs.items()])
287+
arg_str = ', '.join(arg_str)
288+
289+
signature = '%s(%s)' % (name, arg_str)
290+
return module_path, signature
291+
292+
293+
def format_call(func, args, kwargs, object_name="Memory"):
294+
""" Returns a nicely formatted statement displaying the function
295+
call with the given arguments.
296+
"""
297+
path, signature = format_signature(func, *args, **kwargs)
298+
msg = '%s\n[%s] Calling %s...\n%s' % (80 * '_', object_name,
299+
path, signature)
300+
return msg
301+
# XXX: Not using logging framework
302+
#self.debug(msg)

sklearn/externals/joblib/logger.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ def short_format_time(t):
4444
return " %5.1fs" % (t)
4545

4646

47+
def pformat(obj, indent=0, depth=3):
48+
if 'numpy' in sys.modules:
49+
import numpy as np
50+
print_options = np.get_printoptions()
51+
np.set_printoptions(precision=6, threshold=64, edgeitems=1)
52+
else:
53+
print_options = None
54+
out = pprint.pformat(obj, depth=depth, indent=indent)
55+
if print_options:
56+
np.set_printoptions(**print_options)
57+
return out
58+
59+
4760
###############################################################################
4861
# class `Logger`
4962
###############################################################################
@@ -70,16 +83,7 @@ def debug(self, msg):
7083
def format(self, obj, indent=0):
7184
""" Return the formated representation of the object.
7285
"""
73-
if 'numpy' in sys.modules:
74-
import numpy as np
75-
print_options = np.get_printoptions()
76-
np.set_printoptions(precision=6, threshold=64, edgeitems=1)
77-
else:
78-
print_options = None
79-
out = pprint.pformat(obj, depth=self.depth, indent=indent)
80-
if print_options:
81-
np.set_printoptions(**print_options)
82-
return out
86+
return pformat(obj, indent=indent, depth=self.depth)
8387

8488

8589
###############################################################################
@@ -141,8 +145,8 @@ def __call__(self, msg='', total=False):
141145
print(full_msg, file=sys.stderr)
142146
if self.logfile is not None:
143147
try:
144-
with open(self.logfile, 'a') as logfile:
145-
print(full_msg, file=logfile)
148+
with open(self.logfile, 'a') as f:
149+
print(full_msg, file=f)
146150
except:
147151
""" Multiprocessing writing to files can create race
148152
conditions. Rather fail silently than crash the

0 commit comments

Comments
 (0)