16
16
import pandas .tseries .offsets as offsets
17
17
from pandas .compat import lrange , zip
18
18
from pandas .core .indexes .datetimes import bdate_range , date_range
19
- from pandas .core .dtypes .dtypes import DatetimeTZDtype
20
19
from pandas ._libs import tslib
21
20
from 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 ,
23
22
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
26
24
27
25
28
26
class FixedOffset (tzinfo ):
@@ -786,29 +784,6 @@ def test_to_datetime_tzlocal(self):
786
784
result = to_datetime (arr , utc = True )
787
785
assert result .tz is pytz .utc
788
786
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
-
812
787
def test_hongkong_tz_convert (self ):
813
788
# #1673
814
789
dr = date_range ('2012-01-01' , '2012-01-10' , freq = 'D' , tz = 'Hongkong' )
@@ -872,21 +847,6 @@ def test_convert_datetime_list(self):
872
847
assert dr .tz == dr2 .tz
873
848
assert dr2 .name == 'foo'
874
849
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
-
890
850
def test_dateutil_tzoffset_support (self ):
891
851
values = [188.5 , 328.25 ]
892
852
tzinfo = tzoffset (None , 7200 )
@@ -1289,49 +1249,27 @@ def test_tz_localize_roundtrip(self):
1289
1249
tm .assert_index_equal (reset , idx )
1290
1250
assert reset .tzinfo is None
1291
1251
1292
- def test_series_frame_tz_localize (self ):
1252
+ def test_series_tz_localize (self ):
1293
1253
1294
1254
rng = date_range ('1/1/2011' , periods = 100 , freq = 'H' )
1295
1255
ts = Series (1 , index = rng )
1296
1256
1297
1257
result = ts .tz_localize ('utc' )
1298
1258
assert result .index .tz .zone == 'UTC'
1299
1259
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
-
1311
1260
# Can't localize if already tz-aware
1312
1261
rng = date_range ('1/1/2011' , periods = 100 , freq = 'H' , tz = 'utc' )
1313
1262
ts = Series (1 , index = rng )
1314
1263
tm .assert_raises_regex (TypeError , 'Already tz-aware' ,
1315
1264
ts .tz_localize , 'US/Eastern' )
1316
1265
1317
- def test_series_frame_tz_convert (self ):
1266
+ def test_series_tz_convert (self ):
1318
1267
rng = date_range ('1/1/2011' , periods = 200 , freq = 'D' , tz = 'US/Eastern' )
1319
1268
ts = Series (1 , index = rng )
1320
1269
1321
1270
result = ts .tz_convert ('Europe/Berlin' )
1322
1271
assert result .index .tz .zone == 'Europe/Berlin'
1323
1272
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
-
1335
1273
# can't convert tz-naive
1336
1274
rng = date_range ('1/1/2011' , periods = 200 , freq = 'D' )
1337
1275
ts = Series (1 , index = rng )
@@ -1389,20 +1327,6 @@ def test_join_aware(self):
1389
1327
pytest .raises (Exception , ts .__add__ , ts_utc )
1390
1328
pytest .raises (Exception , ts_utc .__add__ , ts )
1391
1329
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
-
1406
1330
# non-overlapping
1407
1331
rng = date_range ("2012-11-15 00:00:00" , periods = 6 , freq = "H" ,
1408
1332
tz = "US/Central" )
@@ -1413,34 +1337,13 @@ def test_join_aware(self):
1413
1337
result = rng .union (rng2 )
1414
1338
assert result .tz .zone == 'UTC'
1415
1339
1416
- def test_align_aware (self ):
1340
+ def test_series_align_aware (self ):
1417
1341
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' )
1425
1344
# # different timezones convert to UTC
1426
1345
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 )
1444
1347
assert new1 .index .tz == pytz .UTC
1445
1348
assert new2 .index .tz == pytz .UTC
1446
1349
@@ -1523,7 +1426,7 @@ def test_append_aware_naive(self):
1523
1426
assert ts_result .index .equals (ts1 .index .astype (object ).append (
1524
1427
ts2 .index ))
1525
1428
1526
- def test_equal_join_ensure_utc (self ):
1429
+ def test_series_add_tz_mismatch_converts_to_utc (self ):
1527
1430
rng = date_range ('1/1/2011' , periods = 10 , freq = 'H' , tz = 'US/Eastern' )
1528
1431
ts = Series (np .random .randn (len (rng )), index = rng )
1529
1432
@@ -1535,14 +1438,6 @@ def test_equal_join_ensure_utc(self):
1535
1438
result = ts_moscow + ts
1536
1439
assert result .index .tz is pytz .utc
1537
1440
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
-
1546
1441
def test_arith_utc_convert (self ):
1547
1442
rng = date_range ('1/1/2011' , periods = 100 , freq = 'H' , tz = 'utc' )
1548
1443
0 commit comments