11import unittest
22from datetime import datetime , timedelta
3+ from zoneinfo import ZoneInfo
34
45import pandas as pd
56from numpy import nan
@@ -27,7 +28,7 @@ def test_make_pandas_basic(self):
2728 self .assertEqual (out [2 ][0 ], start + 3 * dt2 )
2829
2930 ## First Tick
30- idx = pd .DatetimeIndex ([start + dt2 ])
31+ idx = pd .DatetimeIndex ([start + dt2 ], dtype = "datetime64[ns]" )
3132 target = pd .DataFrame ({"x" : [2 ], "y" : [1 ]}, index = idx )
3233 pd .testing .assert_frame_equal (out1 [0 ][1 ], target )
3334 pd .testing .assert_frame_equal (out2 [0 ][1 ], target )
@@ -37,7 +38,7 @@ def test_make_pandas_basic(self):
3738 # Notes:
3839 # - pandas is a bit inconsistent with whether or not it sets freq on the DateTimeIndex, so we drop for comparison.
3940 # - when there is missing data in an integer column, it uses float NaN and hence the column becomes float type
40- idx = pd .DatetimeIndex ([start + dt2 , start + dt2 + dt1 , start + dt2 + 2 * dt1 ])
41+ idx = pd .DatetimeIndex ([start + dt2 , start + dt2 + dt1 , start + dt2 + 2 * dt1 ], dtype = "datetime64[ns]" )
4142 target = pd .DataFrame ({"x" : [2 , 3 , 4 ], "y" : [1.0 , nan , 2.0 ]}, index = idx )
4243 out1 [1 ][1 ].index .freq = None
4344 pd .testing .assert_frame_equal (out1 [1 ][1 ], target )
@@ -50,7 +51,8 @@ def test_make_pandas_basic(self):
5051
5152 ## Third Tick
5253 idx = pd .DatetimeIndex (
53- [start + dt2 , start + dt2 + dt1 , start + dt2 + 2 * dt1 , start + dt2 + 3 * dt1 , start + dt2 + 4 * dt1 ]
54+ [start + dt2 , start + dt2 + dt1 , start + dt2 + 2 * dt1 , start + dt2 + 3 * dt1 , start + dt2 + 4 * dt1 ],
55+ dtype = "datetime64[ns]" ,
5456 )
5557 target = pd .DataFrame ({"x" : [2 , 3 , 4 , 5 , 6 ], "y" : [1.0 , nan , 2.0 , nan , 3.0 ]}, index = idx )
5658 out1 [2 ][1 ].index .freq = None
@@ -83,7 +85,7 @@ def test_make_pandas_window(self):
8385 self .assertEqual (out [1 ][0 ], start + 2 * dt2 )
8486
8587 ## First Tick
86- idx = pd .DatetimeIndex ([start + dt2 ])
88+ idx = pd .DatetimeIndex ([start + dt2 ], dtype = "datetime64[ns]" )
8789 target = pd .DataFrame ({"x" : [2 ], "y" : [1 ]}, index = idx )
8890 pd .testing .assert_frame_equal (out1 [0 ][1 ], target )
8991 pd .testing .assert_frame_equal (out2 [0 ][1 ], target )
@@ -93,17 +95,17 @@ def test_make_pandas_window(self):
9395 # Notes:
9496 # - pandas is a bit inconsistent with whether or not it sets freq on the DateTimeIndex, so we drop for comparison.
9597 # - when there is missing data in an integer column, it uses float NaN and hence the column becomes float type
96- idx = pd .DatetimeIndex ([start + dt2 , start + dt2 + dt1 , start + dt2 + 2 * dt1 ])
98+ idx = pd .DatetimeIndex ([start + dt2 , start + dt2 + dt1 , start + dt2 + 2 * dt1 ], dtype = "datetime64[ns]" )
9799 target = pd .DataFrame ({"x" : [nan , 3.0 , 4.0 ], "y" : [1.0 , nan , 2.0 ]}, index = idx )
98100 out1 [1 ][1 ].index .freq = None
99101 pd .testing .assert_frame_equal (out1 [1 ][1 ], target )
100102
101- idx = pd .DatetimeIndex ([start + dt2 + dt1 , start + dt2 + 2 * dt1 ])
103+ idx = pd .DatetimeIndex ([start + dt2 + dt1 , start + dt2 + 2 * dt1 ], dtype = "datetime64[ns]" )
102104 target = pd .DataFrame ({"x" : [3 , 4 ], "y" : [nan , 2.0 ]}, index = idx )
103105 out2 [1 ][1 ].index .freq = None
104106 pd .testing .assert_frame_equal (out2 [1 ][1 ], target )
105107
106- idx = pd .DatetimeIndex ([start + dt2 + 2 * dt1 ])
108+ idx = pd .DatetimeIndex ([start + dt2 + 2 * dt1 ], dtype = "datetime64[ns]" )
107109 target = pd .DataFrame ({"x" : [4 ], "y" : [2 ]}, index = idx )
108110 out3 [1 ][1 ].index .freq = None
109111 pd .testing .assert_frame_equal (out3 [1 ][1 ], target )
@@ -135,19 +137,19 @@ def test_make_pandas_init(self):
135137 target = pd .DataFrame ({"x" : pd .Series (dtype = "int64" ), "y" : pd .Series (dtype = "int64" )}, index = idx )
136138 pd .testing .assert_frame_equal (out1 [0 ][1 ], target )
137139
138- idx = pd .DatetimeIndex ([start + dt1 ])
140+ idx = pd .DatetimeIndex ([start + dt1 ], dtype = "datetime64[ns]" )
139141 target = pd .DataFrame ({"x" : [1 ], "y" : [nan ]}, index = idx )
140142 pd .testing .assert_frame_equal (out1 [1 ][1 ], target )
141143 pd .testing .assert_frame_equal (out1 [2 ][1 ], target )
142144
143- idx = pd .DatetimeIndex ([start + dt1 , start + dt2 ])
145+ idx = pd .DatetimeIndex ([start + dt1 , start + dt2 ], dtype = "datetime64[ns]" )
144146 target = pd .DataFrame ({"x" : [1 , 2 ], "y" : [nan , 1.0 ]}, index = idx )
145147 pd .testing .assert_frame_equal (out1 [3 ][1 ], target )
146148
147149 ## out2
148150 self .assertEqual (len (out2 ), 1 )
149151 self .assertEqual (out2 [0 ][0 ], start + dt2 )
150- idx = pd .DatetimeIndex ([start + dt2 ])
152+ idx = pd .DatetimeIndex ([start + dt2 ], dtype = "datetime64[ns]" )
151153 target = pd .DataFrame ({"x" : [2 ], "y" : [1 ]}, index = idx )
152154 out2 [0 ][1 ].index .freq = None
153155 pd .testing .assert_frame_equal (out2 [0 ][1 ], target )
@@ -201,9 +203,16 @@ def test_pandas_ts_types(self):
201203 df = csp .DataFrame ({("A" , "x" ): x , ("B" , "x" ): csp .const ("Test" ), ("A" , "y" ): y , ("B" , "y" ): csp .const (start )})
202204 out = csp .run (lambda : df .to_pandas_ts (("A" , "y" ), 2 , ("A" , "x" )), starttime = start , endtime = end )[0 ]
203205 self .assertEqual (len (out ), 3 )
204- idx = pd .DatetimeIndex ([start + dt2 + dt1 , start + dt2 + 2 * dt1 ])
206+ idx = pd .DatetimeIndex ([start + dt2 + dt1 , start + dt2 + 2 * dt1 ], dtype = "datetime64[ns]" )
205207 target = pd .DataFrame (
206- {("A" , "x" ): [3 , 4 ], ("B" , "x" ): ["Test" , "Test" ], ("A" , "y" ): [1 , 2 ], ("B" , "y" ): [start , start ]},
208+ {
209+ ("A" , "x" ): [3 , 4 ],
210+ ("B" , "x" ): ["Test" , "Test" ],
211+ ("A" , "y" ): [1 , 2 ],
212+ ("B" , "y" ): [
213+ pd .Timestamp (start .replace (tzinfo = ZoneInfo ("UTC" )).timestamp () * 1e9 , unit = "ns" ) for i in range (2 )
214+ ],
215+ },
207216 index = idx ,
208217 )
209218 self .assertEqual (out [1 ][0 ], start + dt2 + 2 * dt1 )
0 commit comments