File: test_pandas.py

package info (click to toggle)
python-pubchempy 1.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 388 kB
  • sloc: python: 1,377; makefile: 147
file content (73 lines) | stat: -rw-r--r-- 1,890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
"""
test_pandas
~~~~~~~~~~~

Test optional pandas functionality.

"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pytest

from pubchempy import *


log = logging.getLogger(__name__)


# Import pandas as pd, skipping tests in this module if pandas is not installed
pd = pytest.importorskip('pandas')


def test_compounds_dataframe():
    """"""
    df = get_compounds('C20H41Br', 'formula', as_dataframe=True)
    assert df.ndim == 2
    assert df.index.names == ['cid']
    assert len(df.index) > 5
    columns = df.columns.values.tolist()
    assert 'atom_stereo_count' in columns
    assert 'atoms' in columns
    assert 'canonical_smiles' in columns
    assert 'exact_mass' in columns


def test_substances_dataframe():
    df = get_substances([1, 2, 3, 4], as_dataframe=True)
    assert df.ndim == 2
    assert df.index.names == ['sid']
    assert len(df.index) == 4
    assert df.columns.values.tolist() == ['source_id', 'source_name', 'standardized_cid', 'synonyms']


def test_properties_dataframe():
    df = get_properties(['isomeric_smiles', 'xlogp', 'inchikey'], '1,2,3,4', 'cid', as_dataframe=True)
    assert df.ndim == 2
    assert df.index.names == ['CID']
    assert len(df.index) == 4
    assert df.columns.values.tolist() == ['InChIKey', 'IsomericSMILES', 'XLogP']


def test_compound_series():
    s = Compound.from_cid(241).to_series()
    assert isinstance(s, pd.Series)


def test_substance_series():
    s = Substance.from_sid(1234).to_series()
    assert isinstance(s, pd.Series)


def test_compound_to_frame():
    s = compounds_to_frame(Compound.from_cid(241))
    assert isinstance(s, pd.DataFrame)


def test_substance_to_frame():
    s = substances_to_frame(Substance.from_sid(1234))
    assert isinstance(s, pd.DataFrame)