1616import pandas .tseries .offsets as offsets
1717from pandas .compat import lrange , zip
1818from pandas .core .indexes .datetimes import bdate_range , date_range
19- from pandas .core .dtypes .dtypes import DatetimeTZDtype
2019from pandas ._libs import tslib
2120from pandas ._libs .tslibs import timezones , conversion
22- from pandas import (Index , Series , DataFrame , isna , Timestamp , NaT ,
21+ from pandas import (Index , Series , isna , Timestamp , NaT ,
2322 DatetimeIndex , to_datetime )
24- from pandas .util .testing import (assert_frame_equal , assert_series_equal ,
25- set_timezone )
23+ from pandas .util .testing import assert_series_equal , set_timezone
2624
2725
2826class FixedOffset (tzinfo ):
@@ -786,29 +784,6 @@ def test_to_datetime_tzlocal(self):
786784 result = to_datetime (arr , utc = True )
787785 assert result .tz is pytz .utc
788786
789- def test_frame_no_datetime64_dtype (self ):
790-
791- # after 7822
792- # these retain the timezones on dict construction
793-
794- dr = date_range ('2011/1/1' , '2012/1/1' , freq = 'W-FRI' )
795- dr_tz = dr .tz_localize (self .tzstr ('US/Eastern' ))
796- e = DataFrame ({'A' : 'foo' , 'B' : dr_tz }, index = dr )
797- tz_expected = DatetimeTZDtype ('ns' , dr_tz .tzinfo )
798- assert e ['B' ].dtype == tz_expected
799-
800- # GH 2810 (with timezones)
801- datetimes_naive = [ts .to_pydatetime () for ts in dr ]
802- datetimes_with_tz = [ts .to_pydatetime () for ts in dr_tz ]
803- df = DataFrame ({'dr' : dr ,
804- 'dr_tz' : dr_tz ,
805- 'datetimes_naive' : datetimes_naive ,
806- 'datetimes_with_tz' : datetimes_with_tz })
807- result = df .get_dtype_counts ().sort_index ()
808- expected = Series ({'datetime64[ns]' : 2 ,
809- str (tz_expected ): 2 }).sort_index ()
810- assert_series_equal (result , expected )
811-
812787 def test_hongkong_tz_convert (self ):
813788 # #1673
814789 dr = date_range ('2012-01-01' , '2012-01-10' , freq = 'D' , tz = 'Hongkong' )
@@ -872,21 +847,6 @@ def test_convert_datetime_list(self):
872847 assert dr .tz == dr2 .tz
873848 assert dr2 .name == 'foo'
874849
875- def test_frame_from_records_utc (self ):
876- rec = {'datum' : 1.5 ,
877- 'begin_time' : datetime (2006 , 4 , 27 , tzinfo = pytz .utc )}
878-
879- # it works
880- DataFrame .from_records ([rec ], index = 'begin_time' )
881-
882- def test_frame_reset_index (self ):
883- dr = date_range ('2012-06-02' , periods = 10 , tz = self .tzstr ('US/Eastern' ))
884- df = DataFrame (np .random .randn (len (dr )), dr )
885- roundtripped = df .reset_index ().set_index ('index' )
886- xp = df .index .tz
887- rs = roundtripped .index .tz
888- assert xp == rs
889-
890850 def test_dateutil_tzoffset_support (self ):
891851 values = [188.5 , 328.25 ]
892852 tzinfo = tzoffset (None , 7200 )
@@ -1289,49 +1249,27 @@ def test_tz_localize_roundtrip(self):
12891249 tm .assert_index_equal (reset , idx )
12901250 assert reset .tzinfo is None
12911251
1292- def test_series_frame_tz_localize (self ):
1252+ def test_series_tz_localize (self ):
12931253
12941254 rng = date_range ('1/1/2011' , periods = 100 , freq = 'H' )
12951255 ts = Series (1 , index = rng )
12961256
12971257 result = ts .tz_localize ('utc' )
12981258 assert result .index .tz .zone == 'UTC'
12991259
1300- df = DataFrame ({'a' : 1 }, index = rng )
1301- result = df .tz_localize ('utc' )
1302- expected = DataFrame ({'a' : 1 }, rng .tz_localize ('UTC' ))
1303- assert result .index .tz .zone == 'UTC'
1304- assert_frame_equal (result , expected )
1305-
1306- df = df .T
1307- result = df .tz_localize ('utc' , axis = 1 )
1308- assert result .columns .tz .zone == 'UTC'
1309- assert_frame_equal (result , expected .T )
1310-
13111260 # Can't localize if already tz-aware
13121261 rng = date_range ('1/1/2011' , periods = 100 , freq = 'H' , tz = 'utc' )
13131262 ts = Series (1 , index = rng )
13141263 tm .assert_raises_regex (TypeError , 'Already tz-aware' ,
13151264 ts .tz_localize , 'US/Eastern' )
13161265
1317- def test_series_frame_tz_convert (self ):
1266+ def test_series_tz_convert (self ):
13181267 rng = date_range ('1/1/2011' , periods = 200 , freq = 'D' , tz = 'US/Eastern' )
13191268 ts = Series (1 , index = rng )
13201269
13211270 result = ts .tz_convert ('Europe/Berlin' )
13221271 assert result .index .tz .zone == 'Europe/Berlin'
13231272
1324- df = DataFrame ({'a' : 1 }, index = rng )
1325- result = df .tz_convert ('Europe/Berlin' )
1326- expected = DataFrame ({'a' : 1 }, rng .tz_convert ('Europe/Berlin' ))
1327- assert result .index .tz .zone == 'Europe/Berlin'
1328- assert_frame_equal (result , expected )
1329-
1330- df = df .T
1331- result = df .tz_convert ('Europe/Berlin' , axis = 1 )
1332- assert result .columns .tz .zone == 'Europe/Berlin'
1333- assert_frame_equal (result , expected .T )
1334-
13351273 # can't convert tz-naive
13361274 rng = date_range ('1/1/2011' , periods = 200 , freq = 'D' )
13371275 ts = Series (1 , index = rng )
@@ -1389,20 +1327,6 @@ def test_join_aware(self):
13891327 pytest .raises (Exception , ts .__add__ , ts_utc )
13901328 pytest .raises (Exception , ts_utc .__add__ , ts )
13911329
1392- test1 = DataFrame (np .zeros ((6 , 3 )),
1393- index = date_range ("2012-11-15 00:00:00" , periods = 6 ,
1394- freq = "100L" , tz = "US/Central" ))
1395- test2 = DataFrame (np .zeros ((3 , 3 )),
1396- index = date_range ("2012-11-15 00:00:00" , periods = 3 ,
1397- freq = "250L" , tz = "US/Central" ),
1398- columns = lrange (3 , 6 ))
1399-
1400- result = test1 .join (test2 , how = 'outer' )
1401- ex_index = test1 .index .union (test2 .index )
1402-
1403- tm .assert_index_equal (result .index , ex_index )
1404- assert result .index .tz .zone == 'US/Central'
1405-
14061330 # non-overlapping
14071331 rng = date_range ("2012-11-15 00:00:00" , periods = 6 , freq = "H" ,
14081332 tz = "US/Central" )
@@ -1413,34 +1337,13 @@ def test_join_aware(self):
14131337 result = rng .union (rng2 )
14141338 assert result .tz .zone == 'UTC'
14151339
1416- def test_align_aware (self ):
1340+ def test_series_align_aware (self ):
14171341 idx1 = date_range ('2001' , periods = 5 , freq = 'H' , tz = 'US/Eastern' )
1418- idx2 = date_range ('2001' , periods = 5 , freq = '2H' , tz = 'US/Eastern' )
1419- df1 = DataFrame (np .random .randn (len (idx1 ), 3 ), idx1 )
1420- df2 = DataFrame (np .random .randn (len (idx2 ), 3 ), idx2 )
1421- new1 , new2 = df1 .align (df2 )
1422- assert df1 .index .tz == new1 .index .tz
1423- assert df2 .index .tz == new2 .index .tz
1424-
1342+ ser = Series (np .random .randn (len (idx1 )), index = idx1 )
1343+ ser_central = ser .tz_convert ('US/Central' )
14251344 # # different timezones convert to UTC
14261345
1427- # frame
1428- df1_central = df1 .tz_convert ('US/Central' )
1429- new1 , new2 = df1 .align (df1_central )
1430- assert new1 .index .tz == pytz .UTC
1431- assert new2 .index .tz == pytz .UTC
1432-
1433- # series
1434- new1 , new2 = df1 [0 ].align (df1_central [0 ])
1435- assert new1 .index .tz == pytz .UTC
1436- assert new2 .index .tz == pytz .UTC
1437-
1438- # combination
1439- new1 , new2 = df1 .align (df1_central [0 ], axis = 0 )
1440- assert new1 .index .tz == pytz .UTC
1441- assert new2 .index .tz == pytz .UTC
1442-
1443- df1 [0 ].align (df1_central , axis = 0 )
1346+ new1 , new2 = ser .align (ser_central )
14441347 assert new1 .index .tz == pytz .UTC
14451348 assert new2 .index .tz == pytz .UTC
14461349
@@ -1523,7 +1426,7 @@ def test_append_aware_naive(self):
15231426 assert ts_result .index .equals (ts1 .index .astype (object ).append (
15241427 ts2 .index ))
15251428
1526- def test_equal_join_ensure_utc (self ):
1429+ def test_series_add_tz_mismatch_converts_to_utc (self ):
15271430 rng = date_range ('1/1/2011' , periods = 10 , freq = 'H' , tz = 'US/Eastern' )
15281431 ts = Series (np .random .randn (len (rng )), index = rng )
15291432
@@ -1535,14 +1438,6 @@ def test_equal_join_ensure_utc(self):
15351438 result = ts_moscow + ts
15361439 assert result .index .tz is pytz .utc
15371440
1538- df = DataFrame ({'a' : ts })
1539- df_moscow = df .tz_convert ('Europe/Moscow' )
1540- result = df + df_moscow
1541- assert result .index .tz is pytz .utc
1542-
1543- result = df_moscow + df
1544- assert result .index .tz is pytz .utc
1545-
15461441 def test_arith_utc_convert (self ):
15471442 rng = date_range ('1/1/2011' , periods = 100 , freq = 'H' , tz = 'utc' )
15481443
0 commit comments