2020from pandas ._libs .tslibs .timezones import get_timezone
2121from pandas ._libs .tslibs import conversion
2222
23- from pandas .compat import lrange , long , PY3
23+ from pandas .compat import long , PY3
2424from pandas .util .testing import assert_series_equal
2525from pandas .compat .numpy import np_datetime64_compat
2626from pandas import (Timestamp , date_range , Period , Timedelta , compat ,
27- Series , NaT , DataFrame , DatetimeIndex )
27+ Series , NaT , DataFrame )
2828from pandas .tseries .frequencies import (RESO_DAY , RESO_HR , RESO_MIN , RESO_US ,
2929 RESO_MS , RESO_SEC )
3030
@@ -1227,8 +1227,7 @@ def test_addition_subtraction_types(self):
12271227 timedelta_instance = timedelta (seconds = 1 )
12281228 # build a timestamp with a frequency, since then it supports
12291229 # 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' )
12321231
12331232 assert type (timestamp_instance + 1 ) == Timestamp
12341233 assert type (timestamp_instance - 1 ) == Timestamp
@@ -1246,7 +1245,7 @@ def test_addition_subtraction_types(self):
12461245 assert type (timestamp_instance - timedelta64_instance ) == Timestamp
12471246
12481247 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' )
12501249 timedelta_instance = timedelta (days = 1 )
12511250 original_freq = timestamp_instance .freq
12521251
@@ -1330,30 +1329,10 @@ def test_timestamp_to_datetime_explicit_dateutil(self):
13301329 assert stamp == dtval
13311330 assert stamp .tzinfo == dtval .tzinfo
13321331
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-
13491332 def test_timestamp_date_out_of_range (self ):
13501333 pytest .raises (ValueError , Timestamp , '1676-01-01' )
13511334 pytest .raises (ValueError , Timestamp , '2263-01-01' )
13521335
1353- # see gh-1475
1354- pytest .raises (ValueError , DatetimeIndex , ['1400-01-01' ])
1355- pytest .raises (ValueError , DatetimeIndex , [datetime (1400 , 1 , 1 )])
1356-
13571336 def test_timestamp_repr (self ):
13581337 # pre-1900
13591338 stamp = Timestamp ('1850-01-01' , tz = 'US/Eastern' )
@@ -1422,16 +1401,6 @@ def test_series_box_timestamp(self):
14221401
14231402 assert isinstance (s .iat [5 ], Timestamp )
14241403
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-
14351404 def test_to_html_timestamp (self ):
14361405 rng = date_range ('2000-01-01' , periods = 10 )
14371406 df = DataFrame (np .random .randn (10 , 4 ), index = rng )
@@ -1451,21 +1420,6 @@ def f(x):
14511420 s .apply (f )
14521421 DataFrame (s ).applymap (f )
14531422
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-
14691423 def test_woy_boundary (self ):
14701424 # make sure weeks at year boundaries are correct
14711425 d = datetime (2013 , 12 , 31 )
@@ -1521,58 +1475,3 @@ def test_to_datetime_bijective(self):
15211475 with tm .assert_produces_warning (exp_warning , check_stacklevel = False ):
15221476 assert (Timestamp (Timestamp .min .to_pydatetime ()).value / 1000 ==
15231477 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