-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_pandas.py
58 lines (43 loc) · 1.79 KB
/
test_pandas.py
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
"""
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
"""
import pytest
from simplesqlite import connect_memdb
from ._common import print_test_result
try:
import pandas as pd
PANDAS_IMPORT = True
except ImportError:
PANDAS_IMPORT = False
@pytest.mark.skipif(not PANDAS_IMPORT, reason="required package not found")
class Test_fromto_pandas_dataframe:
def test_normal(self):
con = connect_memdb()
dataframe = pd.DataFrame(
[[0, 0.1, "a"], [1, 1.1, "bb"], [2, 2.2, "ccc"]], columns=["id", "value", "name"]
)
table_name = "tablename"
con.create_table_from_dataframe(dataframe, table_name)
actual_all = con.select_as_dataframe(table_name=table_name)
print_test_result(expected=dataframe, actual=actual_all)
assert actual_all.equals(dataframe)
select_columns = ["value", "name"]
actual_part = con.select_as_dataframe(table_name=table_name, columns=select_columns)
assert actual_part.equals(
pd.DataFrame([[0.1, "a"], [1.1, "bb"], [2.2, "ccc"]], columns=select_columns)
)
def test_normal_include_datetime(self):
con = connect_memdb()
table_name = "table_w_datetime"
dataframe = pd.DataFrame(
[
["2020-03-25 15:24:00-04:00", 0, 0.1, "a"],
["2020-03-25 15:25:00-04:00", 1, 1.1, "bb"],
["2020-03-25 15:30:00-04:00", 2, 2.2, "ccc"],
],
columns=["timestamp", "id", "value", "name"],
)
dataframe["timestamp"] = pd.to_datetime(dataframe["timestamp"])
con.create_table_from_dataframe(dataframe, table_name=table_name)
actual_all = con.select_as_dataframe(table_name=table_name)
print_test_result(expected=dataframe, actual=actual_all)