|
1
|
|
|
#! /usr/bin/env python |
|
2
|
|
|
# |
|
3
|
|
|
# Copyright (C) 2016 Rich Lewis <[email protected]> |
|
4
|
|
|
# License: 3-clause BSD |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
""" |
|
8
|
|
|
# skchem.utils.decorators |
|
9
|
|
|
|
|
10
|
|
|
Decorators for skchem functions. |
|
11
|
|
|
""" |
|
12
|
|
|
|
|
13
|
|
|
import pandas as pd |
|
|
|
|
|
|
14
|
|
|
from functools import wraps |
|
15
|
|
|
|
|
16
|
|
|
from .. import core |
|
17
|
|
|
|
|
18
|
|
|
def takes_mol_series(func): |
|
|
|
|
|
|
19
|
|
|
@wraps(func) |
|
20
|
|
|
@takes_pandas |
|
21
|
|
|
def inner(inp, *args, **kwargs): |
|
|
|
|
|
|
22
|
|
|
if isinstance(inp, pd.DataFrame): |
|
23
|
|
|
inp = inp.structure |
|
24
|
|
|
return func(inp, *args, **kwargs) |
|
25
|
|
|
return inner |
|
26
|
|
|
|
|
27
|
|
|
def method_takes_mol_series(func): |
|
|
|
|
|
|
28
|
|
|
@wraps(func) |
|
29
|
|
|
def inner(self, *args, **kwargs): |
|
|
|
|
|
|
30
|
|
|
return takes_mol_series(lambda *args, **kwargs: func(self, *args, **kwargs))(*args, **kwargs) |
|
|
|
|
|
|
31
|
|
|
return inner |
|
32
|
|
|
|
|
33
|
|
|
def takes_pandas(func): |
|
|
|
|
|
|
34
|
|
|
@wraps(func) |
|
35
|
|
|
def inner(inp, *args, **kwargs): |
|
|
|
|
|
|
36
|
|
|
single = False |
|
37
|
|
|
if isinstance(inp, core.Mol): |
|
38
|
|
|
single = True |
|
39
|
|
|
inp = pd.Series({inp.name: inp}) |
|
40
|
|
|
elif isinstance(inp, (list, tuple)): |
|
41
|
|
|
inp = pd.Series(inp, index=[mol.name for mol in inp]) |
|
42
|
|
|
elif isinstance(inp, dict): |
|
43
|
|
|
inp = pd.Series(inp) |
|
44
|
|
|
elif isinstance(inp, (pd.Series, pd.DataFrame)): |
|
45
|
|
|
pass |
|
46
|
|
|
else: |
|
47
|
|
|
raise NotImplementedError('{} cannot take object of type: {}'.format(func.__name__, type(inp))) |
|
|
|
|
|
|
48
|
|
|
res = func(inp, *args, **kwargs) |
|
49
|
|
|
if single: |
|
50
|
|
|
return res.iloc[0] |
|
51
|
|
|
else: |
|
52
|
|
|
return res |
|
53
|
|
|
return inner |
|
54
|
|
|
|
|
55
|
|
|
def method_takes_pandas(func): |
|
|
|
|
|
|
56
|
|
|
@wraps(func) |
|
57
|
|
|
def inner(self, *args, **kwargs): |
|
|
|
|
|
|
58
|
|
|
return takes_pandas(lambda *args, **kwargs: func(self, *args, **kwargs))(*args, **kwargs) |
|
|
|
|
|
|
59
|
|
|
return inner |
|
60
|
|
|
|
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.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.