Issues (942)

skchem/utils/helpers.py (8 issues)

1
#! /usr/bin/env python
2
#
3
# Copyright (C) 2015-2016 Rich Lewis <[email protected]>
4
# License: 3-clause BSD
5
6 1
"""
7
skchem.utils.helpers
8
9
Module providing helper functions for scikit-chem
10
"""
11
12 1
from collections import Iterable
13 1
from functools import wraps
14
15 1
import numpy as np
0 ignored issues
show
The import numpy could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
16 1
import pandas as pd
0 ignored issues
show
The import pandas could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
17
18
19 1
def optional_second_method(func):
0 ignored issues
show
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
20 1
    @wraps(func)
21 1
    def inner(self, arg, second_arg=None, **kwargs):
0 ignored issues
show
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
22 1
        res = func(self, arg, **kwargs)
23 1
        if second_arg is not None:
24
            return res, second_arg
25
        else:
26 1
            return res
27 1
    return inner
28
29
30 1
def iterable_to_series(mols):
0 ignored issues
show
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
31 1
    assert isinstance(mols, Iterable), 'Object must be iterable.'
32 1
    assert not isinstance(mols, str), 'Object cannot be a string.'
33 1
    if isinstance(mols, dict):
34 1
        return pd.Series(mols, name='structure')
35
    else:
36 1
        return pd.Series(mols, index=[mol.name if mol.name else i
37
                                      for i, mol in enumerate(mols)],
38
                         name='structure')
39
40
41 1
def nanarray(shape):
42
    """ Produce an array of NaN in provided shape.
43
44
    Args:
45
        shape (tuple):
46
            The shape of the nan array to produce.
47
48
    Returns:
49
        np.array
50
51
    """
52 1
    return np.repeat(np.nan, np.prod(shape)).reshape(*shape)
0 ignored issues
show
Usage of * or ** arguments should usually be done with care.

Generally, there is nothing wrong with usage of * or ** arguments. For readability of the code base, we suggest to not over-use these language constructs though.

For more information, we can recommend this blog post from Ned Batchelder including its comments which also touches this aspect.

Loading history...
53
54
55 1
def squeeze(data, axis=None):
56
57
    """ Squeeze dimension for length 1 arrays.
58
59
    Args:
60
        data (pd.Series or pd.DataFrame or pd.Panel):
61
            The pandas object to squeeze.
62
        axis (int or tuple):
63
            The axes along which to squeeze.
64
65
    Returns:
66
        pd.Series or pd.DataFrame
67
    """
68
69 1
    if axis is None:
70
        axis = range(len(data.axes))
71 1
    elif isinstance(axis, int):
72 1
        axis = (axis,)
73 1
    return data.iloc[tuple([0 if len(a) == 1 and i in axis else slice(None)
74
                            for i, a in enumerate(data.axes)])]
75
76
77 1
class Defaults(object):
0 ignored issues
show
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
78
79 1
    def __init__(self, defaults):
80
81 1
        self.defaults = defaults
82
83 1
    def get(self, val):
0 ignored issues
show
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
84 1
        if isinstance(val, str):
85 1
            return self.defaults.get(val)
86
        else:
87 1
            return val
88
89