1
|
|
|
#! /usr/bin/env python |
2
|
|
|
# |
3
|
|
|
# Copyright (C) 2007-2009 Rich Lewis <[email protected]> |
4
|
|
|
# License: 3-clause BSD |
5
|
|
|
|
6
|
|
|
""" # skchem.pandas.structure_methods |
7
|
|
|
|
8
|
|
|
Tools for adding a default attribute to pandas objects.""" |
9
|
|
|
|
10
|
|
|
from pandas.core.base import NoNewAttributesMixin, AccessorProperty |
|
|
|
|
11
|
|
|
from pandas.core.series import Series |
|
|
|
|
12
|
|
|
from pandas.core.index import Index |
|
|
|
|
13
|
|
|
|
14
|
|
|
from .. import core |
15
|
|
|
|
16
|
|
|
class StructureMethods(NoNewAttributesMixin): |
|
|
|
|
17
|
|
|
def __init__(self, data): |
18
|
|
|
self._data = data |
19
|
|
|
|
20
|
|
|
def add_hs(self, **kwargs): |
|
|
|
|
21
|
|
|
return self._data.apply(lambda m: m.add_hs(**kwargs)) |
|
|
|
|
22
|
|
|
|
23
|
|
|
def remove_hs(self, **kwargs): |
|
|
|
|
24
|
|
|
return self._data.apply(lambda m: m.remove_hs(**kwargs)) |
|
|
|
|
25
|
|
|
|
26
|
|
|
@property |
27
|
|
|
def atoms(self): |
|
|
|
|
28
|
|
|
return self._data.apply(lambda m: m.atoms) |
29
|
|
|
|
30
|
|
|
def only_contains_mols(ser): |
|
|
|
|
31
|
|
|
return ser.apply(lambda s: isinstance(s, core.Mol)).all() |
32
|
|
|
|
33
|
|
|
class StructureAccessorMixin(object): |
|
|
|
|
34
|
|
|
|
35
|
|
|
def _make_structure_accessor(self): |
36
|
|
|
if isinstance(self, Index): |
37
|
|
|
raise AttributeError('Can only use .mol accessor with molecules,' |
38
|
|
|
'which use np.object_ in scikit-chem.') |
39
|
|
|
if not only_contains_mols(self): |
40
|
|
|
raise AttributeError('Can only use .mol accessor with ' |
41
|
|
|
'Series that only contain mols.') |
42
|
|
|
|
43
|
|
|
return StructureMethods(self) |
44
|
|
|
ms = AccessorProperty(StructureMethods, _make_structure_accessor) |
|
|
|
|
45
|
|
|
|
46
|
|
|
|
47
|
|
|
Series.__bases__ += StructureAccessorMixin, |
48
|
|
|
|
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__.py
files in your module folders. Make sure that you place one file in each sub-folder.