MOEDescriptorCalculator._transform_series()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 9.933

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 17
ccs 1
cts 12
cp 0.0833
rs 9.4285
cc 3
crap 9.933
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.descriptors.moe
8
9
Module specifying moe descriptors.
10
"""
11
12 1
class MOEDescriptorCalculator(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...
13
14 1
    def __init__(self):
15
        pass
16
17 1
    def transform(self, obj):
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...
18
        if isinstance(obj, core.Mol):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'core'
Loading history...
19
            return self._transform_series(pd.Series(obj)).iloc[0]
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'pd'
Loading history...
20
        elif isinstance(obj, pd.Series):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'pd'
Loading history...
21
            return self._transform_series(obj)
22
        elif isinstance(obj, pd.DataFrame):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'pd'
Loading history...
23
            return self._transform_series(obj.structure)
24
        elif isinstance(obj, (tuple, list)):
25
            return self._transform_series(obj)
26
        else:
27
            raise NotImplementedError
28
29 1
    def _transform_series(self, series):
30
31
        with tempfile.NamedTemporaryFile(suffix='.sdf') as in_file, tempfile.NamedTemporaryFile() as out_file:
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'tempfile'
Loading history...
32
            # write mols to file
33
            write_sdf(series, in_file.name)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'write_sdf'
Loading history...
34
            args = ['mddesc', in_file.name, '-o', out_file.name] + self.index
0 ignored issues
show
Bug introduced by
The Instance of MOEDescriptorCalculator does not seem to have a member named index.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
35
36
            LOGGER.info('Running: ' + ' '.join(args))
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'LOGGER'
Loading history...
37
38
            # call command line
39
            subprocess.call(args)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'subprocess'
Loading history...
40
            try:
41
                finished = pd.read_table(out_file.name).set_index('id')
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'pd'
Loading history...
42
            except Exception:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
43
                finished = None
44
        finished.index = series.index
45
        return finished
46
47
48