20
20
from pandas ._libs .tslibs .timezones import get_timezone
21
21
from pandas ._libs .tslibs import conversion
22
22
23
- from pandas .compat import lrange , long , PY3
23
+ from pandas .compat import long , PY3
24
24
from pandas .util .testing import assert_series_equal
25
25
from pandas .compat .numpy import np_datetime64_compat
26
26
from pandas import (Timestamp , date_range , Period , Timedelta , compat ,
27
- Series , NaT , DataFrame , DatetimeIndex )
27
+ Series , NaT , DataFrame )
28
28
from pandas .tseries .frequencies import (RESO_DAY , RESO_HR , RESO_MIN , RESO_US ,
29
29
RESO_MS , RESO_SEC )
30
30
@@ -1227,8 +1227,7 @@ def test_addition_subtraction_types(self):
1227
1227
timedelta_instance = timedelta (seconds = 1 )
1228
1228
# build a timestamp with a frequency, since then it supports
1229
1229
# addition/subtraction of integers
1230
- timestamp_instance = date_range (datetime_instance , periods = 1 ,
1231
- freq = 'D' )[0 ]
1230
+ timestamp_instance = Timestamp (datetime_instance , freq = 'D' )
1232
1231
1233
1232
assert type (timestamp_instance + 1 ) == Timestamp
1234
1233
assert type (timestamp_instance - 1 ) == Timestamp
@@ -1246,7 +1245,7 @@ def test_addition_subtraction_types(self):
1246
1245
assert type (timestamp_instance - timedelta64_instance ) == Timestamp
1247
1246
1248
1247
def test_addition_subtraction_preserve_frequency (self ):
1249
- timestamp_instance = date_range ('2014-03-05' , periods = 1 , freq = 'D' )[ 0 ]
1248
+ timestamp_instance = Timestamp ('2014-03-05' , freq = 'D' )
1250
1249
timedelta_instance = timedelta (days = 1 )
1251
1250
original_freq = timestamp_instance .freq
1252
1251
@@ -1330,30 +1329,10 @@ def test_timestamp_to_datetime_explicit_dateutil(self):
1330
1329
assert stamp == dtval
1331
1330
assert stamp .tzinfo == dtval .tzinfo
1332
1331
1333
- def test_timestamp_fields (self ):
1334
- # extra fields from DatetimeIndex like quarter and week
1335
- idx = tm .makeDateIndex (100 )
1336
-
1337
- fields = ['dayofweek' , 'dayofyear' , 'week' , 'weekofyear' , 'quarter' ,
1338
- 'days_in_month' , 'is_month_start' , 'is_month_end' ,
1339
- 'is_quarter_start' , 'is_quarter_end' , 'is_year_start' ,
1340
- 'is_year_end' , 'weekday_name' ]
1341
- for f in fields :
1342
- expected = getattr (idx , f )[- 1 ]
1343
- result = getattr (Timestamp (idx [- 1 ]), f )
1344
- assert result == expected
1345
-
1346
- assert idx .freq == Timestamp (idx [- 1 ], idx .freq ).freq
1347
- assert idx .freqstr == Timestamp (idx [- 1 ], idx .freq ).freqstr
1348
-
1349
1332
def test_timestamp_date_out_of_range (self ):
1350
1333
pytest .raises (ValueError , Timestamp , '1676-01-01' )
1351
1334
pytest .raises (ValueError , Timestamp , '2263-01-01' )
1352
1335
1353
- # see gh-1475
1354
- pytest .raises (ValueError , DatetimeIndex , ['1400-01-01' ])
1355
- pytest .raises (ValueError , DatetimeIndex , [datetime (1400 , 1 , 1 )])
1356
-
1357
1336
def test_timestamp_repr (self ):
1358
1337
# pre-1900
1359
1338
stamp = Timestamp ('1850-01-01' , tz = 'US/Eastern' )
@@ -1422,16 +1401,6 @@ def test_series_box_timestamp(self):
1422
1401
1423
1402
assert isinstance (s .iat [5 ], Timestamp )
1424
1403
1425
- def test_frame_setitem_timestamp (self ):
1426
- # 2155
1427
- columns = DatetimeIndex (start = '1/1/2012' , end = '2/1/2012' ,
1428
- freq = offsets .BDay ())
1429
- index = lrange (10 )
1430
- data = DataFrame (columns = columns , index = index )
1431
- t = datetime (2012 , 11 , 1 )
1432
- ts = Timestamp (t )
1433
- data [ts ] = np .nan # works
1434
-
1435
1404
def test_to_html_timestamp (self ):
1436
1405
rng = date_range ('2000-01-01' , periods = 10 )
1437
1406
df = DataFrame (np .random .randn (10 , 4 ), index = rng )
@@ -1451,21 +1420,6 @@ def f(x):
1451
1420
s .apply (f )
1452
1421
DataFrame (s ).applymap (f )
1453
1422
1454
- def test_dti_slicing (self ):
1455
- dti = DatetimeIndex (start = '1/1/2005' , end = '12/1/2005' , freq = 'M' )
1456
- dti2 = dti [[1 , 3 , 5 ]]
1457
-
1458
- v1 = dti2 [0 ]
1459
- v2 = dti2 [1 ]
1460
- v3 = dti2 [2 ]
1461
-
1462
- assert v1 == Timestamp ('2/28/2005' )
1463
- assert v2 == Timestamp ('4/30/2005' )
1464
- assert v3 == Timestamp ('6/30/2005' )
1465
-
1466
- # don't carry freq through irregular slicing
1467
- assert dti2 .freq is None
1468
-
1469
1423
def test_woy_boundary (self ):
1470
1424
# make sure weeks at year boundaries are correct
1471
1425
d = datetime (2013 , 12 , 31 )
@@ -1521,58 +1475,3 @@ def test_to_datetime_bijective(self):
1521
1475
with tm .assert_produces_warning (exp_warning , check_stacklevel = False ):
1522
1476
assert (Timestamp (Timestamp .min .to_pydatetime ()).value / 1000 ==
1523
1477
Timestamp .min .value / 1000 )
1524
-
1525
-
1526
- class TestTimestampEquivDateRange (object ):
1527
- # Older tests in TestTimeSeries constructed their `stamp` objects
1528
- # using `date_range` instead of the `Timestamp` constructor.
1529
- # TestTimestampEquivDateRange checks that these are equivalent in the
1530
- # pertinent cases.
1531
-
1532
- def test_date_range_timestamp_equiv (self ):
1533
- rng = date_range ('20090415' , '20090519' , tz = 'US/Eastern' )
1534
- stamp = rng [0 ]
1535
-
1536
- ts = Timestamp ('20090415' , tz = 'US/Eastern' , freq = 'D' )
1537
- assert ts == stamp
1538
-
1539
- def test_date_range_timestamp_equiv_dateutil (self ):
1540
- rng = date_range ('20090415' , '20090519' , tz = 'dateutil/US/Eastern' )
1541
- stamp = rng [0 ]
1542
-
1543
- ts = Timestamp ('20090415' , tz = 'dateutil/US/Eastern' , freq = 'D' )
1544
- assert ts == stamp
1545
-
1546
- def test_date_range_timestamp_equiv_explicit_pytz (self ):
1547
- rng = date_range ('20090415' , '20090519' ,
1548
- tz = pytz .timezone ('US/Eastern' ))
1549
- stamp = rng [0 ]
1550
-
1551
- ts = Timestamp ('20090415' , tz = pytz .timezone ('US/Eastern' ), freq = 'D' )
1552
- assert ts == stamp
1553
-
1554
- def test_date_range_timestamp_equiv_explicit_dateutil (self ):
1555
- tm ._skip_if_windows_python_3 ()
1556
- from pandas ._libs .tslibs .timezones import dateutil_gettz as gettz
1557
-
1558
- rng = date_range ('20090415' , '20090519' , tz = gettz ('US/Eastern' ))
1559
- stamp = rng [0 ]
1560
-
1561
- ts = Timestamp ('20090415' , tz = gettz ('US/Eastern' ), freq = 'D' )
1562
- assert ts == stamp
1563
-
1564
- def test_date_range_timestamp_equiv_from_datetime_instance (self ):
1565
- datetime_instance = datetime (2014 , 3 , 4 )
1566
- # build a timestamp with a frequency, since then it supports
1567
- # addition/subtraction of integers
1568
- timestamp_instance = date_range (datetime_instance , periods = 1 ,
1569
- freq = 'D' )[0 ]
1570
-
1571
- ts = Timestamp (datetime_instance , freq = 'D' )
1572
- assert ts == timestamp_instance
1573
-
1574
- def test_date_range_timestamp_equiv_preserve_frequency (self ):
1575
- timestamp_instance = date_range ('2014-03-05' , periods = 1 , freq = 'D' )[0 ]
1576
- ts = Timestamp ('2014-03-05' , freq = 'D' )
1577
-
1578
- assert timestamp_instance == ts
0 commit comments