6
6
import json
7
7
import requests_mock
8
8
from nose .tools import raises
9
- from datetime import datetime , timedelta
10
- import time
9
+ from datetime import timedelta
11
10
from tests import skipIfPYpy , using_pypy
12
11
13
12
if not using_pypy :
22
21
class TestDataFrameClient (unittest .TestCase ):
23
22
24
23
def test_write_points_from_dataframe (self ):
25
- now = datetime ( 2014 , 11 , 15 , 15 , 42 , 44 , 543 )
24
+ now = pd . Timestamp ( '1970-01-01 00:00+00:00' )
26
25
dataframe = pd .DataFrame (data = [["1" , 1 , 1.0 ], ["2" , 2 , 2.0 ]],
27
26
index = [now , now + timedelta (hours = 1 )],
28
27
columns = ["column_one" , "column_two" ,
29
28
"column_three" ])
30
29
points = [
31
30
{
32
31
"points" : [
33
- ["1" , 1 , 1.0 , time .mktime (now .timetuple ())],
34
- ["2" , 2 , 2.0 , time .mktime ((now + timedelta (hours = 1 ))
35
- .timetuple ())]
32
+ ["1" , 1 , 1.0 , 0 ],
33
+ ["2" , 2 , 2.0 , 3600 ]
36
34
],
37
35
"name" : "foo" ,
38
36
"columns" : ["column_one" , "column_two" , "column_three" , "time" ]
@@ -49,16 +47,15 @@ def test_write_points_from_dataframe(self):
49
47
self .assertListEqual (json .loads (m .last_request .body ), points )
50
48
51
49
def test_write_points_from_dataframe_with_numeric_column_names (self ):
52
- now = datetime ( 2014 , 11 , 15 , 15 , 42 , 44 , 543 )
50
+ now = pd . Timestamp ( '1970-01-01 00:00+00:00' )
53
51
# df with numeric column names
54
52
dataframe = pd .DataFrame (data = [["1" , 1 , 1.0 ], ["2" , 2 , 2.0 ]],
55
53
index = [now , now + timedelta (hours = 1 )])
56
54
points = [
57
55
{
58
56
"points" : [
59
- ["1" , 1 , 1.0 , time .mktime (now .timetuple ())],
60
- ["2" , 2 , 2.0 , time .mktime ((now + timedelta (hours = 1 ))
61
- .timetuple ())]
57
+ ["1" , 1 , 1.0 , 0 ],
58
+ ["2" , 2 , 2.0 , 3600 ]
62
59
],
63
60
"name" : "foo" ,
64
61
"columns" : ['0' , '1' , '2' , "time" ]
@@ -75,18 +72,16 @@ def test_write_points_from_dataframe_with_numeric_column_names(self):
75
72
self .assertListEqual (json .loads (m .last_request .body ), points )
76
73
77
74
def test_write_points_from_dataframe_with_period_index (self ):
78
- now = datetime (2014 , 11 , 16 )
79
75
dataframe = pd .DataFrame (data = [["1" , 1 , 1.0 ], ["2" , 2 , 2.0 ]],
80
- index = [pd .Period ('2014-11-16 ' ),
81
- pd .Period ('2014-11-17 ' )],
76
+ index = [pd .Period ('1970-01-01 ' ),
77
+ pd .Period ('1970-01-02 ' )],
82
78
columns = ["column_one" , "column_two" ,
83
79
"column_three" ])
84
80
points = [
85
81
{
86
82
"points" : [
87
- ["1" , 1 , 1.0 , time .mktime (now .timetuple ())],
88
- ["2" , 2 , 2.0 , time .mktime ((now + timedelta (hours = 24 ))
89
- .timetuple ())]
83
+ ["1" , 1 , 1.0 , 0 ],
84
+ ["2" , 2 , 2.0 , 86400 ]
90
85
],
91
86
"name" : "foo" ,
92
87
"columns" : ["column_one" , "column_two" , "column_three" , "time" ]
@@ -117,7 +112,7 @@ def test_write_points_from_dataframe_fails_without_time_index(self):
117
112
118
113
@raises (TypeError )
119
114
def test_write_points_from_dataframe_fails_with_series (self ):
120
- now = datetime ( 2014 , 11 , 16 )
115
+ now = pd . Timestamp ( '1970-01-01 00:00+00:00' )
121
116
dataframe = pd .Series (data = [1.0 , 2.0 ],
122
117
index = [now , now + timedelta (hours = 1 )])
123
118
0 commit comments