8000 [MRG+2] Add sklearn show_versions() method by aboucaud · Pull Request #11596 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG+2] Add sklearn show_versions() method #11596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
83c7074
add preliminary show_versions method
aboucaud Jul 17, 2018
7a7d831
address Roman's comments
aboucaud Jul 17, 2018
7aebdcd
refactor file
aboucaud Jul 17, 2018
86ffe08
add tests
aboucaud Jul 17, 2018
42b82ad
change function scope
aboucaud Jul 18, 2018
d19ce86
refactor after rth and lesteve comments
aboucaud Jul 18, 2018
31962d2
update unit tests
aboucaud Jul 18, 2018
a94cd5f
fix flake8
aboucaud Jul 18, 2018
48aeebb
delay import till after setup
aboucaud Jul 18, 2018
40f8cea
Update rst docs
aboucaud Jul 19, 2018
dc41e60
add entry to whats new
aboucaud Jul 19, 2018
4af0921
Merge branch 'master' into show-versions
aboucaud Jul 19, 2018
637bdbd
fix appveyor
aboucaud Jul 19, 2018
24c4b82
address Roman's comments
aboucaud Jul 19, 2018
c363987
fix flake8
aboucaud Jul 19, 2018
b89114a
change numpy version call
aboucaud Jul 20, 2018
8b8d566
attempt to make appveyor happy
aboucaud Jul 20, 2018
df9ccce
move import
aboucaud Jul 22, 2018
a8eb7c5
remove matplotlib
aboucaud Jul 22, 2018
f07866a
revert what's new doc
aboucaud Jul 22, 2018
563a728
add note for versions pre 0.20
aboucaud Jul 22, 2018
b64015d
manually remove ChainedImputer entry
aboucaud Jul 22, 2018
8923f0b
remove matplotlib from tests
aboucaud Jul 22, 2018
19605c3
added to the function list in classes.rst
aboucaud Jul 23, 2018
902c5f9
remove module version getter redundancy
aboucaud Jul 24, 2018
7d8f1ac
Modify docstring
aboucaud Jul 24, 2018
842930e
address roman's comment
aboucaud Jul 24, 2018
91086d7
rename module
aboucaud Jul 24, 2018
48c9a2f
Restore end of line whitespace
aboucaud Jul 31, 2018
b7a793d
address Gael's comment
aboucaud Jul 31, 2018
5f0fb51
Fix typo
aboucaud Jul 31, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/developers/contributing.rst
10000
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ feedback:
your **Python, scikit-learn, numpy, and scipy versions**. This information
can be found by running the following code snippet::

>>> import sklearn
>>> sklearn.show_versions() # doctest: +SKIP

.. note::

This utility function is only available in scikit-learn v0.20+.
For previous versions, one has to explicitly run::

import platform; print(platform.platform())
import sys; print("Python", sys.version)
import numpy; print("NumPy", numpy.__version__)
Expand Down
10 changes: 3 additions & 7 deletions doc/developers/tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,11 @@ Issue: Self-contained example for bug
Issue: Software versions
::

To help diagnose your issue, could you please paste the output of:
To help diagnose your issue, please paste the output of:
```py
import platform; print(platform.platform())
import sys; print("Python", sys.version)
import numpy; print("NumPy", numpy.__version__)
import scipy; print("SciPy", scipy.__version__)
import sklearn; print("Scikit-Learn", sklearn.__version__)
import sklearn; sklearn.show_versions()
```
? Thanks.
Thanks.

Issue: Code blocks
::
Expand Down
1 change: 1 addition & 0 deletions doc/modules/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Functions
config_context
get_config
set_config
show_versions

.. _calibration_ref:

Expand Down
6 changes: 6 additions & 0 deletions doc/whats_new/v0.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ Misc
exposed in :mod:`sklearn.utils`.
:issue:`11166`by `Gael Varoquaux`_

- A utility method :func:`sklearn.show_versions()` was added to print out
information relevant for debugging. It includes the user system, the
Python executable, the version of the main libraries and BLAS binding
information.
:issue:`11596` by :user:`Alexandre Boucaud <aboucaud>`

Enhancements
............

Expand Down
5 changes: 4 additions & 1 deletion sklearn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
else:
from . import __check_build
from .base import clone
from .utils._show_versions import show_versions

__check_build # avoid flakes unused variable error

__all__ = ['calibration', 'cluster', 'covariance', 'cross_decomposition',
Expand All @@ -74,7 +76,8 @@
'preprocessing', 'random_projection', 'semi_supervised',
'svm', 'tree', 'discriminant_analysis', 'impute', 'compose',
# Non-modules:
'clone', 'get_config', 'set_config', 'config_context']
'clone', 'get_config', 'set_config', 'config_context',
'show_versions']


def setup_module(module):
Expand Down
119 changes: 119 additions & 0 deletions sklearn/utils/_show_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
"""
Utility methods to print system info for debugging

adapted from :func:`pandas.show_versions`
"""
# License: BSD 3 clause

import platform
import sys
import importlib


def _get_sys_info():
"""System information

Return
------
sys_info : dict
system and Python version information

"""
python = sys.version.replace('\n', ' ')

blob = [
("python", python),
('executable', sys.executable),
("machine", platform.platform()),
]

return dict(blob)


def _get_deps_info():
"""Overview of the installed version of main dependencies

Returns
-------
deps_info: dict
version information on relevant Python libraries

"""
deps = [
"pip",
"setuptools",
"sklearn",
"numpy",
"scipy",
"Cython",
"pandas",
]

def get_version(module):
return module.__version__

deps_info = {}

for modname in deps:
try:
if modname in sys.modules:
mod = sys.modules[modname]
else:
mod = importlib.import_module(modname)
ver = get_version(mod)
deps_info[modname] = ver
except ImportError:
deps_info[modname] = None

return deps_info


def _get_blas_info():
"""Information on system BLAS

Uses the `scikit-learn` builtin method
:func:`sklearn._build_utils.get_blas_info` which may fail from time to time

Returns
-------
blas_info: dict
system BLAS information

"""
from .._build_utils import get_blas_info

cblas_libs, blas_dict = get_blas_info()

macros = ['{key}={val}'.format(key=a, val=b)
for (a, b) in blas_dict.get('define_macros', [])]

blas_blob = [
('macros', ', '.join(macros)),
('lib_dirs', ':'.join(blas_dict.get('library_dirs', ''))),
('cblas_libs', ', '.join(cblas_libs)),
]

return dict(blas_blob)


def show_versions():
"Print useful debugging information"

sys_info = _get_sys_info()
deps_info = _get_deps_info()
blas_info = _get_blas_info()

print('\nSystem')
print('------')
for k, stat in sys_info.items():
print("{k:>10}: {stat}".format(k=k, stat=stat))

print('\nBLAS')
print('----')
for k, stat in blas_info.items():
print("{k:>10}: {stat}".format(k=k, stat=stat))

print('\nPython deps')
print('-----------')
for k, stat in deps_info.items():
print("{k:>10}: {stat}".format(k=k, stat=stat))
32 changes: 32 additions & 0 deletions sklearn/utils/tests/test_print_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

from sklearn.utils._show_versions import _get_sys_info
from sklearn.utils._show_versions import _get_deps_info
from sklearn.utils._show_versions import show_versions


def test_get_sys_info():
sys_info = _get_sys_info()

assert 'python' in sys_info
assert 'executable' in sys_info
assert 'machine' in sys_info


def test_get_deps_info():
deps_info = _get_deps_info()

assert 'pip' in deps_info
assert 'setuptools' in deps_info
assert 'sklearn' in deps_info
assert 'numpy' in deps_info
assert 'scipy' in deps_info
assert 'Cython' in deps_info
assert 'pandas' in deps_info


def test_show_versions_with_blas(capsys):
show_versions()
out, err = capsys.readouterr()
assert 'python' in out
assert 'numpy' in out
assert 'BLAS' in out
0