@@ -600,7 +600,7 @@ def test_pprint(self):
600600 'foo': 1}"""
601601 assert result == expected
602602
603- def to_datetime_depr (self ):
603+ def test_to_datetime_depr (self ):
604604 # see gh-8254
605605 ts = Timestamp ('2011-01-01' )
606606
@@ -610,7 +610,7 @@ def to_datetime_depr(self):
610610 result = ts .to_datetime ()
611611 assert result == expected
612612
613- def to_pydatetime_nonzero_nano (self ):
613+ def test_to_pydatetime_nonzero_nano (self ):
614614 ts = Timestamp ('2011-01-01 9:00:00.123456789' )
615615
616616 # Warn the user of data loss (nanoseconds).
@@ -987,35 +987,6 @@ def test_delta_preserve_nanos(self):
987987 result = val + timedelta (1 )
988988 assert result .nanosecond == val .nanosecond
989989
990- def test_frequency_misc (self ):
991- assert (frequencies .get_freq_group ('T' ) ==
992- frequencies .FreqGroup .FR_MIN )
993-
994- code , stride = frequencies .get_freq_code (offsets .Hour ())
995- assert code == frequencies .FreqGroup .FR_HR
996-
997- code , stride = frequencies .get_freq_code ((5 , 'T' ))
998- assert code == frequencies .FreqGroup .FR_MIN
999- assert stride == 5
1000-
1001- offset = offsets .Hour ()
1002- result = frequencies .to_offset (offset )
1003- assert result == offset
1004-
1005- result = frequencies .to_offset ((5 , 'T' ))
1006- expected = offsets .Minute (5 )
1007- assert result == expected
1008-
1009- pytest .raises (ValueError , frequencies .get_freq_code , (5 , 'baz' ))
1010-
1011- pytest .raises (ValueError , frequencies .to_offset , '100foo' )
1012-
1013- pytest .raises (ValueError , frequencies .to_offset , ('' , '' ))
1014-
1015- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
1016- result = frequencies .get_standard_freq (offsets .Hour ())
1017- assert result == 'H'
1018-
1019990 def test_hash_equivalent (self ):
1020991 d = {datetime (2011 , 1 , 1 ): 5 }
1021992 stamp = Timestamp (datetime (2011 , 1 , 1 ))
@@ -1303,26 +1274,19 @@ def test_compare_hour13(self):
13031274class TestTimeSeries (object ):
13041275
13051276 def test_timestamp_to_datetime (self ):
1306- rng = date_range ('20090415' , '20090519' , tz = 'US/Eastern' )
1307-
1308- stamp = rng [0 ]
1277+ stamp = Timestamp ('20090415' , tz = 'US/Eastern' , freq = 'D' )
13091278 dtval = stamp .to_pydatetime ()
13101279 assert stamp == dtval
13111280 assert stamp .tzinfo == dtval .tzinfo
13121281
13131282 def test_timestamp_to_datetime_dateutil (self ):
1314- rng = date_range ('20090415' , '20090519' , tz = 'dateutil/US/Eastern' )
1315-
1316- stamp = rng [0 ]
1283+ stamp = Timestamp ('20090415' , tz = 'dateutil/US/Eastern' , freq = 'D' )
13171284 dtval = stamp .to_pydatetime ()
13181285 assert stamp == dtval
13191286 assert stamp .tzinfo == dtval .tzinfo
13201287
13211288 def test_timestamp_to_datetime_explicit_pytz (self ):
1322- rng = date_range ('20090415' , '20090519' ,
1323- tz = pytz .timezone ('US/Eastern' ))
1324-
1325- stamp = rng [0 ]
1289+ stamp = Timestamp ('20090415' , tz = pytz .timezone ('US/Eastern' ), freq = 'D' )
13261290 dtval = stamp .to_pydatetime ()
13271291 assert stamp == dtval
13281292 assert stamp .tzinfo == dtval .tzinfo
@@ -1331,9 +1295,7 @@ def test_timestamp_to_datetime_explicit_dateutil(self):
13311295 tm ._skip_if_windows_python_3 ()
13321296
13331297 from pandas ._libs .tslibs .timezones import dateutil_gettz as gettz
1334- rng = date_range ('20090415' , '20090519' , tz = gettz ('US/Eastern' ))
1335-
1336- stamp = rng [0 ]
1298+ stamp = Timestamp ('20090415' , tz = gettz ('US/Eastern' ), freq = 'D' )
13371299 dtval = stamp .to_pydatetime ()
13381300 assert stamp == dtval
13391301 assert stamp .tzinfo == dtval .tzinfo
@@ -1529,3 +1491,58 @@ def test_to_datetime_bijective(self):
15291491 with tm .assert_produces_warning (exp_warning , check_stacklevel = False ):
15301492 assert (Timestamp (Timestamp .min .to_pydatetime ()).value / 1000 ==
15311493 Timestamp .min .value / 1000 )
1494+
1495+
1496+ class TestTimestampEquivDateRange (object ):
1497+ # Older tests in TestTimeSeries constructed their `stamp` objects
1498+ # using `date_range` instead of the `Timestamp` constructor.
1499+ # TestTimestampEquivDateRange checks that these are equivalent in the
1500+ # pertinent cases.
1501+
1502+ def test_date_range_timestamp_equiv (self ):
1503+ rng = date_range ('20090415' , '20090519' , tz = 'US/Eastern' )
1504+ stamp = rng [0 ]
1505+
1506+ ts = Timestamp ('20090415' , tz = 'US/Eastern' , freq = 'D' )
1507+ assert ts == stamp
1508+
1509+ def test_date_range_timestamp_equiv_dateutil (self ):
1510+ rng = date_range ('20090415' , '20090519' , tz = 'dateutil/US/Eastern' )
1511+ stamp = rng [0 ]
1512+
1513+ ts = Timestamp ('20090415' , tz = 'dateutil/US/Eastern' , freq = 'D' )
1514+ assert ts == stamp
1515+
1516+ def test_date_range_timestamp_equiv_explicit_pytz (self ):
1517+ rng = date_range ('20090415' , '20090519' ,
1518+ tz = pytz .timezone ('US/Eastern' ))
1519+ stamp = rng [0 ]
1520+
1521+ ts = Timestamp ('20090415' , tz = pytz .timezone ('US/Eastern' ), freq = 'D' )
1522+ assert ts == stamp
1523+
1524+ def test_date_range_timestamp_equiv_explicit_dateutil (self ):
1525+ tm ._skip_if_windows_python_3 ()
1526+ from pandas ._libs .tslibs .timezones import dateutil_gettz as gettz
1527+
1528+ rng = date_range ('20090415' , '20090519' , tz = gettz ('US/Eastern' ))
1529+ stamp = rng [0 ]
1530+
1531+ ts = Timestamp ('20090415' , tz = gettz ('US/Eastern' ), freq = 'D' )
1532+ assert ts == stamp
1533+
1534+ def test_date_range_timestamp_equiv_from_datetime_instance (self ):
1535+ datetime_instance = datetime (2014 , 3 , 4 )
1536+ # build a timestamp with a frequency, since then it supports
1537+ # addition/subtraction of integers
1538+ timestamp_instance = date_range (datetime_instance , periods = 1 ,
1539+ freq = 'D' )[0 ]
1540+
1541+ ts = Timestamp (datetime_instance , freq = 'D' )
1542+ assert ts == timestamp_instance
1543+
1544+ def test_date_range_timestamp_equiv_preserve_frequency (self ):
1545+ timestamp_instance = date_range ('2014-03-05' , periods = 1 , freq = 'D' )[0 ]
1546+ ts = Timestamp ('2014-03-05' , freq = 'D' )
1547+
1548+ assert timestamp_instance == ts
0 commit comments