Completed
Push — master ( 6e14ce...512eb0 )
by Rich
02:12
created

Defaults   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
dl 0
loc 11
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 5 2
A __init__() 0 3 1
1
#! /usr/bin/env python
2
#
3
# Copyright (C) 2015-2016 Rich Lewis <[email protected]>
4
# License: 3-clause BSD
5
6
"""
7
skchem.utils.helpers
8
9
Module providing helper functions for scikit-chem
10
"""
11
12
from collections import Iterable
13
from functools import wraps
14
15
import numpy as np
0 ignored issues
show
Configuration introduced by
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
import pandas as pd
0 ignored issues
show
Configuration introduced by
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
def optional_second_method(func):
0 ignored issues
show
Coding Style introduced by
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
    @wraps(func)
21
    def inner(self, arg, second_arg=None, **kwargs):
0 ignored issues
show
Coding Style introduced by
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
        res = func(self, arg, **kwargs)
23
        if second_arg is not None:
24
            return res, second_arg
25
        else:
26
            return res
27
    return inner
28
29
30
def iterable_to_series(mols):
0 ignored issues
show
Coding Style introduced by
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
    assert isinstance(mols, Iterable), 'Object must be iterable.'
32
    assert not isinstance(mols, str), 'Object cannot be a string.'
33
    if isinstance(mols, dict):
34
        return pd.Series(mols, name='structure')
35
    else:
36
        return pd.Series(mols, index=[mol.name if mol.name else i for i, mol in enumerate(mols)], name='structure')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (115/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
37
38
39
def nanarray(shape):
40
    """ Produce an array of NaN in provided shape.
41
42
    Args:
43
        shape (tuple):
44
            The shape of the nan array to produce.
45
46
    Returns:
47
        np.array
48
49
    """
50
    return np.repeat(np.nan, np.prod(shape)).reshape(*shape)
0 ignored issues
show
Coding Style introduced by
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...
51
52
53
def squeeze(data, axis=None):
54
55
    """ Squeeze dimension for length 1 arrays.
56
57
    Args:
58
        data (pd.Series or pd.DataFrame or pd.Panel):
59
            The pandas object to squeeze.
60
        axis (int or tuple):
61
            The axes along which to squeeze.
62
63
    Returns:
64
        pd.Series or pd.DataFrame
65
    """
66
67
    if axis is None:
68
        axis = range(len(data.axes))
69
    elif isinstance(axis, int):
70
        axis = (axis,)
71
    return data.iloc[tuple([0 if len(a) == 1 and i in axis else slice(None) for i, a in enumerate(data.axes)])]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
72
73
74
class Defaults(object):
0 ignored issues
show
Coding Style introduced by
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...
75
76
    def __init__(self, defaults):
77
78
        self.defaults = defaults
79
80
    def get(self, val):
0 ignored issues
show
Coding Style introduced by
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...
81
        if isinstance(val, str):
82
           return self.defaults.get(val)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 11 were found.
Loading history...
83
        else:
84
            return val
85
86