Completed
Push — master ( c7f259...9726b9 )
by Rich
01:31
created

PhysicochemicalFingerprinter._transform()   A

Complexity

Conditions 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
#! /usr/bin/env python
2
#
3
# Copyright (C) 2007-2009 Rich Lewis <[email protected]>
4
# License: 3-clause BSD
5
6
"""
7
## skchem.descriptors.physicochemical
8
9
Physicochemical descriptors and associated functions are defined.
10
11
"""
12
13
from rdkit.Chem import Descriptors
0 ignored issues
show
Configuration introduced by
The import rdkit.Chem 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...
14
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...
Unused Code introduced by
Unused pandas imported as pd
Loading history...
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
17
from .fingerprints import Fingerprinter
18
from ..utils import camel_to_snail
19
20
DESCRIPTORS = [(camel_to_snail(s), f) for (s, f) in Descriptors.descList]
21
22
class PhysicochemicalFingerprinter(Fingerprinter):
23
24
    """ Physicochemical descriptor generator using RDKit descriptor """
25
26
    NAME = 'physchem'
27
28
    def __init__(self, descriptors='all'):
0 ignored issues
show
Bug introduced by
The __init__ method of the super-class Fingerprinter is not called.

It is generally advisable to initialize the super-class by calling its __init__ method:

class SomeParent:
    def __init__(self):
        self.x = 1

class SomeChild(SomeParent):
    def __init__(self):
        # Initialize the super class
        SomeParent.__init__(self)
Loading history...
29
30
        """ Create a physicochemical descriptor generator.
31
32
        Args:
33
            descriptors (list<(str, func)> or 'all'):
34
                Descriptors to calculate, or if 'all', use all descriptors."""
35
36
        if descriptors == 'all':
37
            self.descriptors = DESCRIPTORS
38
        else:
39
            self.descriptors = descriptors
40
        self.descriptor_names, _ = zip(*self.descriptors)
41
42
    @property
43
    def index(self):
44
        return self.descriptor_names
45
46
    def _transform(self, mol):
47
48
        return np.array([f(mol) for (n, f) in self.descriptors])
0 ignored issues
show
Comprehensibility Bug introduced by
f is re-defining a name which is already available in the outer-scope (previously defined on line 20).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Unused Code introduced by
The variable n seems to be unused.
Loading history...
49