3
3
"""
4
4
import numpy as np
5
5
import pytest
6
- import pytz
7
6
8
7
from pandas .core .dtypes .dtypes import DatetimeTZDtype
9
8
14
13
15
14
16
15
class TestDataFrameTimezones :
17
- def test_frame_values_with_tz (self ):
18
- tz = "US/Central"
19
- df = DataFrame ({"A" : date_range ("2000" , periods = 4 , tz = tz )})
20
- result = df .values
21
- expected = np .array (
22
- [
23
- [pd .Timestamp ("2000-01-01" , tz = tz )],
24
- [pd .Timestamp ("2000-01-02" , tz = tz )],
25
- [pd .Timestamp ("2000-01-03" , tz = tz )],
26
- [pd .Timestamp ("2000-01-04" , tz = tz )],
27
- ]
28
- )
29
- tm .assert_numpy_array_equal (result , expected )
30
-
31
- # two columns, homogenous
32
-
33
- df = df .assign (B = df .A )
34
- result = df .values
35
- expected = np .concatenate ([expected , expected ], axis = 1 )
36
- tm .assert_numpy_array_equal (result , expected )
37
-
38
- # three columns, heterogeneous
39
- est = "US/Eastern"
40
- df = df .assign (C = df .A .dt .tz_convert (est ))
41
-
42
- new = np .array (
43
- [
44
- [pd .Timestamp ("2000-01-01T01:00:00" , tz = est )],
45
- [pd .Timestamp ("2000-01-02T01:00:00" , tz = est )],
46
- [pd .Timestamp ("2000-01-03T01:00:00" , tz = est )],
47
- [pd .Timestamp ("2000-01-04T01:00:00" , tz = est )],
48
- ]
49
- )
50
- expected = np .concatenate ([expected , new ], axis = 1 )
51
- result = df .values
52
- tm .assert_numpy_array_equal (result , expected )
53
-
54
16
def test_frame_join_tzaware (self ):
55
17
test1 = DataFrame (
56
18
np .zeros ((6 , 3 )),
@@ -72,32 +34,6 @@ def test_frame_join_tzaware(self):
72
34
tm .assert_index_equal (result .index , ex_index )
73
35
assert result .index .tz .zone == "US/Central"
74
36
75
- def test_frame_align_aware (self ):
76
- idx1 = date_range ("2001" , periods = 5 , freq = "H" , tz = "US/Eastern" )
77
- idx2 = date_range ("2001" , periods = 5 , freq = "2H" , tz = "US/Eastern" )
78
- df1 = DataFrame (np .random .randn (len (idx1 ), 3 ), idx1 )
79
- df2 = DataFrame (np .random .randn (len (idx2 ), 3 ), idx2 )
80
- new1 , new2 = df1 .align (df2 )
81
- assert df1 .index .tz == new1 .index .tz
82
- assert df2 .index .tz == new2 .index .tz
83
-
84
- # different timezones convert to UTC
85
-
86
- # frame with frame
87
- df1_central = df1 .tz_convert ("US/Central" )
88
- new1 , new2 = df1 .align (df1_central )
89
- assert new1 .index .tz == pytz .UTC
90
- assert new2 .index .tz == pytz .UTC
91
-
92
- # frame with Series
93
- new1 , new2 = df1 .align (df1_central [0 ], axis = 0 )
94
- assert new1 .index .tz == pytz .UTC
95
- assert new2 .index .tz == pytz .UTC
96
-
97
- df1 [0 ].align (df1_central , axis = 0 )
98
- assert new1 .index .tz == pytz .UTC
99
- assert new2 .index .tz == pytz .UTC
100
-
101
37
@pytest .mark .parametrize ("tz" , ["US/Eastern" , "dateutil/US/Eastern" ])
102
38
def test_frame_no_datetime64_dtype (self , tz ):
103
39
# after GH#7822
0 commit comments