<s> from datetime import datetime <EOL> from pandas . compat import range <EOL> import nose <EOL> import numpy as np <EOL> from pandas . core . index import Index <EOL> from pandas . tseries . index import DatetimeIndex <EOL> from pandas import Timestamp <EOL> from pandas . tseries . offsets import generate_range <EOL> from pandas . tseries . index import cdate_range , bdate_range , date_range <EOL> from pandas . core import common as com <EOL> import pandas . core . datetools as datetools <EOL> from pandas . util . testing import assertRaisesRegexp <EOL> import pandas . util . testing as tm <EOL> def eq_gen_range ( kwargs , expected ) : <EOL> rng = generate_range ( ** kwargs ) <EOL> assert ( np . array_equal ( list ( rng ) , expected ) ) <EOL> START , END = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> class TestGenRangeGeneration ( tm . TestCase ) : <EOL> def test_generate ( self ) : <EOL> rng1 = list ( generate_range ( START , END , offset = datetools . bday ) ) <EOL> rng2 = list ( generate_range ( START , END , time_rule = '<STR_LIT:B>' ) ) <EOL> self . assert_numpy_array_equal ( rng1 , rng2 ) <EOL> def test_generate_cday ( self ) : <EOL> rng1 = list ( generate_range ( START , END , offset = datetools . cday ) ) <EOL> rng2 = list ( generate_range ( START , END , time_rule = '<STR_LIT:C>' ) ) <EOL> self . assert_numpy_array_equal ( rng1 , rng2 ) <EOL> def test_1 ( self ) : <EOL> eq_gen_range ( dict ( start = datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) , periods = <NUM_LIT:2> ) , <EOL> [ datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) , datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) ] ) <EOL> def test_2 ( self ) : <EOL> eq_gen_range ( dict ( start = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> end = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> ) ) , <EOL> [ datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> ) , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> ) ] ) <EOL> def test_3 ( self ) : <EOL> eq_gen_range ( dict ( start = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:5> ) , <EOL> end = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:6> ) ) , <EOL> [ ] ) <EOL> def test_precision_finer_than_offset ( self ) : <EOL> result1 = DatetimeIndex ( start = '<STR_LIT>' , <EOL> end = '<STR_LIT>' , freq = '<STR_LIT>' ) <EOL> result2 = DatetimeIndex ( start = '<STR_LIT>' , <EOL> end = '<STR_LIT>' , freq = '<STR_LIT>' ) <EOL> expected1_list = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> expected2_list = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> expected1 = DatetimeIndex ( expected1_list , dtype = '<STR_LIT>' , <EOL> freq = '<STR_LIT>' , tz = None ) <EOL> expected2 = DatetimeIndex ( expected2_list , dtype = '<STR_LIT>' , <EOL> freq = '<STR_LIT>' , tz = None ) <EOL> self . assertTrue ( result1 . equals ( expected1 ) ) <EOL> self . assertTrue ( result2 . equals ( expected2 ) ) <EOL> class TestDateRange ( tm . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . rng = bdate_range ( START , END ) <EOL> def test_constructor ( self ) : <EOL> bdate_range ( START , END , freq = datetools . bday ) <EOL> bdate_range ( START , periods = <NUM_LIT:20> , freq = datetools . bday ) <EOL> bdate_range ( end = START , periods = <NUM_LIT:20> , freq = datetools . bday ) <EOL> self . assertRaises ( ValueError , date_range , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:B>' ) <EOL> self . assertRaises ( ValueError , bdate_range , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:B>' ) <EOL> def test_naive_aware_conflicts ( self ) : <EOL> naive = bdate_range ( START , END , freq = datetools . bday , tz = None ) <EOL> aware = bdate_range ( START , END , freq = datetools . bday , <EOL> tz = "<STR_LIT>" ) <EOL> assertRaisesRegexp ( TypeError , "<STR_LIT>" , naive . join , aware ) <EOL> assertRaisesRegexp ( TypeError , "<STR_LIT>" , aware . join , naive ) <EOL> def test_cached_range ( self ) : <EOL> DatetimeIndex . _cached_range ( START , END , offset = datetools . bday ) <EOL> DatetimeIndex . _cached_range ( START , periods = <NUM_LIT:20> , <EOL> offset = datetools . bday ) <EOL> DatetimeIndex . _cached_range ( end = START , periods = <NUM_LIT:20> , <EOL> offset = datetools . bday ) <EOL> assertRaisesRegexp ( TypeError , "<STR_LIT>" , DatetimeIndex . _cached_range , <EOL> START , END ) <EOL> assertRaisesRegexp ( TypeError , "<STR_LIT>" , <EOL> DatetimeIndex . _cached_range , START , <EOL> offset = datetools . bday ) <EOL> assertRaisesRegexp ( TypeError , "<STR_LIT>" , <EOL> DatetimeIndex . _cached_range , end = END , <EOL> offset = datetools . bday ) <EOL> assertRaisesRegexp ( TypeError , "<STR_LIT>" , <EOL> DatetimeIndex . _cached_range , periods = <NUM_LIT:20> , <EOL> offset = datetools . bday ) <EOL> def test_cached_range_bug ( self ) : <EOL> rng = date_range ( '<STR_LIT>' , periods = <NUM_LIT:50> , <EOL> freq = datetools . DateOffset ( hours = <NUM_LIT:6> ) ) <EOL> self . assertEqual ( len ( rng ) , <NUM_LIT:50> ) <EOL> self . assertEqual ( rng [ <NUM_LIT:0> ] , datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:1> , <NUM_LIT:5> ) ) <EOL> def test_timezone_comparaison_bug ( self ) : <EOL> start = Timestamp ( '<STR_LIT>' , tz = '<STR_LIT>' ) <EOL> try : <EOL> date_range ( start , periods = <NUM_LIT:2> , tz = '<STR_LIT>' ) <EOL> except AssertionError : <EOL> self . fail ( ) <EOL> def test_timezone_comparaison_assert ( self ) : <EOL> start = Timestamp ( '<STR_LIT>' , tz = '<STR_LIT>' ) <EOL> self . assertRaises ( AssertionError , date_range , start , periods = <NUM_LIT:2> , <EOL> tz = '<STR_LIT>' ) <EOL> def test_comparison ( self ) : <EOL> d = self . rng [ <NUM_LIT:10> ] <EOL> comp = self . rng > d <EOL> self . assertTrue ( comp [ <NUM_LIT:11> ] ) <EOL> self . assertFalse ( comp [ <NUM_LIT:9> ] ) <EOL> def test_copy ( self ) : <EOL> cp = self . rng . copy ( ) <EOL> repr ( cp ) <EOL> self . assertTrue ( cp . equals ( self . rng ) ) <EOL> def test_repr ( self ) : <EOL> repr ( self . rng ) <EOL> def test_getitem ( self ) : <EOL> smaller = self . rng [ : <NUM_LIT:5> ] <EOL> self . assert_numpy_array_equal ( smaller , self . rng . view ( np . ndarray ) [ : <NUM_LIT:5> ] ) <EOL> self . assertEqual ( smaller . offset , self . rng . offset ) <EOL> sliced = self . rng [ : : <NUM_LIT:5> ] <EOL> self . assertEqual ( sliced . offset , datetools . bday * <NUM_LIT:5> ) <EOL> fancy_indexed = self . rng [ [ <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] ] <EOL> self . assertEqual ( len ( fancy_indexed ) , <NUM_LIT:5> ) <EOL> tm . assertIsInstance ( fancy_indexed , DatetimeIndex ) <EOL> self . assertIsNone ( fancy_indexed . freq ) <EOL> self . assertEqual ( self . rng [ <NUM_LIT:4> ] , self . rng [ np . int_ ( <NUM_LIT:4> ) ] ) <EOL> def test_getitem_matplotlib_hackaround ( self ) : <EOL> values = self . rng [ : , None ] <EOL> expected = self . rng . values [ : , None ] <EOL> self . assert_numpy_array_equal ( values , expected ) <EOL> def test_shift ( self ) : <EOL> shifted = self . rng . shift ( <NUM_LIT:5> ) <EOL> self . assertEqual ( shifted [ <NUM_LIT:0> ] , self . rng [ <NUM_LIT:5> ] ) <EOL> self . assertEqual ( shifted . offset , self . rng . offset ) <EOL> shifted = self . rng . shift ( - <NUM_LIT:5> ) <EOL> self . assertEqual ( shifted [ <NUM_LIT:5> ] , self . rng [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( shifted . offset , self . rng . offset ) <EOL> shifted = self . rng . shift ( <NUM_LIT:0> ) <EOL> self . assertEqual ( shifted [ <NUM_LIT:0> ] , self . rng [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( shifted . offset , self . rng . offset ) <EOL> rng = date_range ( START , END , freq = datetools . bmonthEnd ) <EOL> shifted = rng . shift ( <NUM_LIT:1> , freq = datetools . bday ) <EOL> self . assertEqual ( shifted [ <NUM_LIT:0> ] , rng [ <NUM_LIT:0> ] + datetools . bday ) <EOL> def test_pickle_unpickle ( self ) : <EOL> unpickled = self . round_trip_pickle ( self . rng ) <EOL> self . assertIsNotNone ( unpickled . offset ) <EOL> def test_union ( self ) : <EOL> left = self . rng [ : <NUM_LIT:10> ] <EOL> right = self . rng [ <NUM_LIT:5> : <NUM_LIT:10> ] <EOL> the_union = left . union ( right ) <EOL> tm . assertIsInstance ( the_union , DatetimeIndex ) <EOL> left = self . rng [ : <NUM_LIT:5> ] <EOL> right = self . rng [ <NUM_LIT:10> : ] <EOL> the_union = left . union ( right ) <EOL> tm . assertIsInstance ( the_union , Index ) <EOL> left = self . rng [ : <NUM_LIT:5> ] <EOL> right = self . rng [ <NUM_LIT:5> : <NUM_LIT:10> ] <EOL> the_union = left . union ( right ) <EOL> tm . assertIsInstance ( the_union , DatetimeIndex ) <EOL> self . assert_numpy_array_equal ( right . union ( left ) , the_union ) <EOL> rng = date_range ( START , END , freq = datetools . bmonthEnd ) <EOL> the_union = self . rng . union ( rng ) <EOL> tm . assertIsInstance ( the_union , DatetimeIndex ) <EOL> def test_outer_join ( self ) : <EOL> left = self . rng [ : <NUM_LIT:10> ] <EOL> right = self . rng [ <NUM_LIT:5> : <NUM_LIT:10> ] <EOL> the_join = left . join ( right , how = '<STR_LIT>' ) <EOL> tm . assertIsInstance ( the_join , DatetimeIndex ) <EOL> left = self . rng [ : <NUM_LIT:5> ] <EOL> right = self . rng [ <NUM_LIT:10> : ] <EOL> the_join = left . join ( right , how = '<STR_LIT>' ) <EOL> tm . assertIsInstance ( the_join , DatetimeIndex ) <EOL> self . assertIsNone ( the_join . freq ) <EOL> left = self . rng [ : <NUM_LIT:5> ] <EOL> right = self . rng [ <NUM_LIT:5> : <NUM_LIT:10> ] <EOL> the_join = left . join ( right , how = '<STR_LIT>' ) <EOL> tm . assertIsInstance ( the_join , DatetimeIndex ) <EOL> rng = date_range ( START , END , freq = datetools . bmonthEnd ) <EOL> the_join = self . rng . join ( rng , how = '<STR_LIT>' ) <EOL> tm . assertIsInstance ( the_join , DatetimeIndex ) <EOL> self . assertIsNone ( the_join . freq ) <EOL> def test_union_not_cacheable ( self ) : <EOL> rng = date_range ( '<STR_LIT>' , periods = <NUM_LIT:50> , freq = datetools . Minute ( ) ) <EOL> rng1 = rng [ <NUM_LIT:10> : ] <EOL> rng2 = rng [ : <NUM_LIT> ] <EOL> the_union = rng1 . union ( rng2 ) <EOL> self . assertTrue ( the_union . equals ( rng ) ) <EOL> rng1 = rng [ <NUM_LIT:10> : ] <EOL> rng2 = rng [ <NUM_LIT:15> : <NUM_LIT> ] <EOL> the_union = rng1 . union ( rng2 ) <EOL> expected = rng [ <NUM_LIT:10> : ] <EOL> self . assertTrue ( the_union . equals ( expected ) ) <EOL> def test_intersection ( self ) : <EOL> rng = date_range ( '<STR_LIT>' , periods = <NUM_LIT:50> , freq = datetools . Minute ( ) ) <EOL> rng1 = rng [ <NUM_LIT:10> : ] <EOL> rng2 = rng [ : <NUM_LIT> ] <EOL> the_int = rng1 . intersection ( rng2 ) <EOL> expected = rng [ <NUM_LIT:10> : <NUM_LIT> ] <EOL> self . assertTrue ( the_int . equals ( expected ) ) <EOL> tm . assertIsInstance ( the_int , DatetimeIndex ) <EOL> self . assertEqual ( the_int . offset , rng . offset ) <EOL> the_int = rng1 . intersection ( rng2 . view ( DatetimeIndex ) ) <EOL> self . assertTrue ( the_int . equals ( expected ) ) <EOL> the_int = rng [ : <NUM_LIT:10> ] . intersection ( rng [ <NUM_LIT:10> : ] ) <EOL> expected = DatetimeIndex ( [ ] ) <EOL> self . assertTrue ( the_int . equals ( expected ) ) <EOL> def test_intersection_bug ( self ) : <EOL> a = bdate_range ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> b = bdate_range ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> result = a . intersection ( b ) <EOL> self . assertTrue ( result . equals ( b ) ) <EOL> def test_summary ( self ) : <EOL> self . rng . summary ( ) <EOL> self . rng [ <NUM_LIT:2> : <NUM_LIT:2> ] . summary ( ) <EOL> def test_summary_pytz ( self ) : <EOL> tm . _skip_if_no_pytz ( ) <EOL> import pytz <EOL> bdate_range ( '<STR_LIT>' , '<STR_LIT>' , tz = pytz . utc ) . summary ( ) <EOL> def test_summary_dateutil ( self ) : <EOL> tm . _skip_if_no_dateutil ( ) <EOL> import dateutil <EOL> bdate_range ( '<STR_LIT>' , '<STR_LIT>' , tz = dateutil . tz . tzutc ( ) ) . summary ( ) <EOL> def test_misc ( self ) : <EOL> end = datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> ) <EOL> dr = bdate_range ( end = end , periods = <NUM_LIT:20> ) <EOL> firstDate = end - <NUM_LIT> * datetools . bday <EOL> assert len ( dr ) == <NUM_LIT:20> <EOL> assert dr [ <NUM_LIT:0> ] == firstDate <EOL> assert dr [ - <NUM_LIT:1> ] == end <EOL> def test_date_parse_failure ( self ) : <EOL> badly_formed_date = '<STR_LIT>' <EOL> self . assertRaises ( ValueError , Timestamp , badly_formed_date ) <EOL> self . assertRaises ( ValueError , bdate_range , start = badly_formed_date , <EOL> periods = <NUM_LIT:10> ) <EOL> self . assertRaises ( ValueError , bdate_range , end = badly_formed_date , <EOL> periods = <NUM_LIT:10> ) <EOL> self . assertRaises ( ValueError , bdate_range , badly_formed_date , <EOL> badly_formed_date ) <EOL> def test_equals ( self ) : <EOL> self . assertFalse ( self . rng . equals ( list ( self . rng ) ) ) <EOL> def test_identical ( self ) : <EOL> t1 = self . rng . copy ( ) <EOL> t2 = self . rng . copy ( ) <EOL> self . assertTrue ( t1 . identical ( t2 ) ) <EOL> t1 = t1 . rename ( '<STR_LIT:foo>' ) <EOL> self . assertTrue ( t1 . equals ( t2 ) ) <EOL> self . assertFalse ( t1 . identical ( t2 ) ) <EOL> t2 = t2 . rename ( '<STR_LIT:foo>' ) <EOL> self . assertTrue ( t1 . identical ( t2 ) ) <EOL> t2v = Index ( t2 . values ) <EOL> self . assertTrue ( t1 . equals ( t2v ) ) <EOL> self . assertFalse ( t1 . identical ( t2v ) ) <EOL> def test_daterange_bug_456 ( self ) : <EOL> rng1 = bdate_range ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> rng2 = bdate_range ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> rng2 . offset = datetools . BDay ( ) <EOL> result = rng1 . union ( rng2 ) <EOL> tm . assertIsInstance ( result , DatetimeIndex ) <EOL> def test_error_with_zero_monthends ( self ) : <EOL> self . assertRaises ( ValueError , date_range , '<STR_LIT>' , '<STR_LIT>' , <EOL> freq = datetools . MonthEnd ( <NUM_LIT:0> ) ) <EOL> def test_range_bug ( self ) : <EOL> offset = datetools . DateOffset ( months = <NUM_LIT:3> ) <EOL> result = date_range ( "<STR_LIT>" , "<STR_LIT>" , freq = offset ) <EOL> start = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> exp_values = [ start + i * offset for i in range ( <NUM_LIT:5> ) ] <EOL> self . assert_numpy_array_equal ( result , DatetimeIndex ( exp_values ) ) <EOL> def test_range_tz_pytz ( self ) : <EOL> tm . _skip_if_no_pytz ( ) <EOL> from pytz import timezone <EOL> tz = timezone ( '<STR_LIT>' ) <EOL> start = tz . localize ( datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> end = tz . localize ( datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> dr = date_range ( start = start , periods = <NUM_LIT:3> ) <EOL> self . assertEqual ( dr . tz . zone , tz . zone ) <EOL> self . assertEqual ( dr [ <NUM_LIT:0> ] , start ) <EOL> self . assertEqual ( dr [ <NUM_LIT:2> ] , end ) <EOL> dr = date_range ( end = end , periods = <NUM_LIT:3> ) <EOL> self . assertEqual ( dr . tz . zone , tz . zone ) <EOL> self . assertEqual ( dr [ <NUM_LIT:0> ] , start ) <EOL> self . assertEqual ( dr [ <NUM_LIT:2> ] , end ) <EOL> dr = date_range ( start = start , end = end ) <EOL> self . assertEqual ( dr . tz . zone , tz . zone ) <EOL> self . assertEqual ( dr [ <NUM_LIT:0> ] , start ) <EOL> self . assertEqual ( dr [ <NUM_LIT:2> ] , end ) <EOL> def test_range_tz_dst_straddle_pytz ( self ) : <EOL> tm . _skip_if_no_pytz ( ) <EOL> from pytz import timezone <EOL> tz = timezone ( '<STR_LIT>' ) <EOL> dates = [ ( tz . localize ( datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:6> ) ) , <EOL> tz . localize ( datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:12> ) ) ) , <EOL> ( tz . localize ( datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:1> ) ) , <EOL> tz . localize ( datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:6> ) ) ) ] <EOL> for ( start , end ) in dates : <EOL> dr = date_range ( start , end , freq = '<STR_LIT:D>' ) <EOL> self . assertEqual ( dr [ <NUM_LIT:0> ] , start ) <EOL> self . assertEqual ( dr [ - <NUM_LIT:1> ] , end ) <EOL> self . assertEqual ( np . all ( dr . hour == <NUM_LIT:0> ) , True ) <EOL> dr = date_range ( start , end , freq = '<STR_LIT:D>' , tz = '<STR_LIT>' ) <EOL> self . assertEqual ( dr [ <NUM_LIT:0> ] , start ) <EOL> self . assertEqual ( dr [ - <NUM_LIT:1> ] , end ) <EOL> self . assertEqual ( np . all ( dr . hour == <NUM_LIT:0> ) , True ) <EOL> dr = date_range ( start . replace ( tzinfo = None ) , end . replace ( <EOL> tzinfo = None ) , freq = '<STR_LIT:D>' , tz = '<STR_LIT>' ) <EOL> self . assertEqual ( dr [ <NUM_LIT:0> ] , start ) <EOL> self . assertEqual ( dr [ - <NUM_LIT:1> ] , end ) <EOL> self . assertEqual ( np . all ( dr . hour == <NUM_LIT:0> ) , True ) <EOL> def test_range_tz_dateutil ( self ) : <EOL> tm . _skip_if_no_dateutil ( ) <EOL> from pandas . tslib import maybe_get_tz <EOL> tz = lambda x : maybe_get_tz ( '<STR_LIT>' + x ) <EOL> start = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = tz ( '<STR_LIT>' ) ) <EOL> end = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> , tzinfo = tz ( '<STR_LIT>' ) ) <EOL> dr = date_range ( start = start , periods = <NUM_LIT:3> ) <EOL> self . assertTrue ( dr . tz == tz ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( dr [ <NUM_LIT:0> ] == start ) <EOL> self . assertTrue ( dr [ <NUM_LIT:2> ] == end ) <EOL> dr = date_range ( end = end , periods = <NUM_LIT:3> ) <EOL> self . assertTrue ( dr . tz == tz ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( dr [ <NUM_LIT:0> ] == start ) <EOL> self . assertTrue ( dr [ <NUM_LIT:2> ] == end ) <EOL> dr = date_range ( start = start , end = end ) <EOL> self . assertTrue ( dr . tz == tz ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( dr [ <NUM_LIT:0> ] == start ) <EOL> self . assertTrue ( dr [ <NUM_LIT:2> ] == end ) <EOL> def test_month_range_union_tz_pytz ( self ) : <EOL> tm . _skip_if_no_pytz ( ) <EOL> from pytz import timezone <EOL> tz = timezone ( '<STR_LIT>' ) <EOL> early_start = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> early_end = datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> late_start = datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> late_end = datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:1> ) <EOL> early_dr = date_range ( start = early_start , end = early_end , tz = tz , <EOL> freq = datetools . monthEnd ) <EOL> late_dr = date_range ( start = late_start , end = late_end , tz = tz , <EOL> freq = datetools . monthEnd ) <EOL> early_dr . union ( late_dr ) <EOL> def test_month_range_union_tz_dateutil ( self ) : <EOL> tm . _skip_if_windows_python_3 ( ) <EOL> tm . _skip_if_no_dateutil ( ) <EOL> from pandas . tslib import _dateutil_gettz as timezone <EOL> tz = timezone ( '<STR_LIT>' ) <EOL> early_start = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> early_end = datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> late_start = datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> late_end = datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:1> ) <EOL> early_dr = date_range ( start = early_start , end = early_end , tz = tz , <EOL> freq = datetools . monthEnd ) <EOL> late_dr = date_range ( start = late_start , end = late_end , tz = tz , <EOL> freq = datetools . monthEnd ) <EOL> early_dr . union ( late_dr ) <EOL> def test_range_closed ( self ) : <EOL> begin = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> end = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> for freq in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:A>" ] : <EOL> closed = date_range ( begin , end , closed = None , freq = freq ) <EOL> left = date_range ( begin , end , closed = "<STR_LIT:left>" , freq = freq ) <EOL> right = date_range ( begin , end , closed = "<STR_LIT:right>" , freq = freq ) <EOL> expected_left = left <EOL> expected_right = right <EOL> if end == closed [ - <NUM_LIT:1> ] : <EOL> expected_left = closed [ : - <NUM_LIT:1> ] <EOL> if begin == closed [ <NUM_LIT:0> ] : <EOL> expected_right = closed [ <NUM_LIT:1> : ] <EOL> self . assertTrue ( expected_left . equals ( left ) ) <EOL> self . assertTrue ( expected_right . equals ( right ) ) <EOL> def test_range_closed_with_tz_aware_start_end ( self ) : <EOL> begin = Timestamp ( '<STR_LIT>' , tz = '<STR_LIT>' ) <EOL> end = Timestamp ( '<STR_LIT>' , tz = '<STR_LIT>' ) <EOL> for freq in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:A>" ] : <EOL> closed = date_range ( begin , end , closed = None , freq = freq ) <EOL> left = date_range ( begin , end , closed = "<STR_LIT:left>" , freq = freq ) <EOL> right = date_range ( begin , end , closed = "<STR_LIT:right>" , freq = freq ) <EOL> expected_left = left <EOL> expected_right = right <EOL> if end == closed [ - <NUM_LIT:1> ] : <EOL> expected_left = closed [ : - <NUM_LIT:1> ] <EOL> if begin == closed [ <NUM_LIT:0> ] : <EOL> expected_right = closed [ <NUM_LIT:1> : ] <EOL> self . assertTrue ( expected_left . equals ( left ) ) <EOL> self . assertTrue ( expected_right . equals ( right ) ) <EOL> begin = Timestamp ( '<STR_LIT>' , tz = '<STR_LIT>' ) <EOL> end = Timestamp ( '<STR_LIT>' , tz = '<STR_LIT>' ) <EOL> intervals = [ '<STR_LIT:left>' , '<STR_LIT:right>' , None ] <EOL> for i in intervals : <EOL> result = date_range ( start = begin , end = end , closed = i ) <EOL> self . assertEqual ( result [ <NUM_LIT:0> ] , begin ) <EOL> self . assertEqual ( result [ - <NUM_LIT:1> ] , end ) <EOL> def test_range_closed_boundary ( self ) : <EOL> for closed in [ '<STR_LIT:right>' , '<STR_LIT:left>' , None ] : <EOL> right_boundary = date_range ( '<STR_LIT>' , '<STR_LIT>' , <EOL> freq = '<STR_LIT>' , closed = closed ) <EOL> left_boundary = date_range ( '<STR_LIT>' , '<STR_LIT>' , <EOL> freq = '<STR_LIT>' , closed = closed ) <EOL> both_boundary = date_range ( '<STR_LIT>' , '<STR_LIT>' , <EOL> freq = '<STR_LIT>' , closed = closed ) <EOL> expected_right = expected_left = expected_both = both_boundary <EOL> if closed == '<STR_LIT:right>' : <EOL> expected_left = both_boundary [ <NUM_LIT:1> : ] <EOL> if closed == '<STR_LIT:left>' : <EOL> expected_right = both_boundary [ : - <NUM_LIT:1> ] <EOL> if closed is None : <EOL> expected_right = both_boundary [ <NUM_LIT:1> : ] <EOL> expected_left = both_boundary [ : - <NUM_LIT:1> ] <EOL> self . assertTrue ( right_boundary . equals ( expected_right ) ) <EOL> self . assertTrue ( left_boundary . equals ( expected_left ) ) <EOL> self . assertTrue ( both_boundary . equals ( expected_both ) ) <EOL> def test_years_only ( self ) : <EOL> dr = date_range ( '<STR_LIT>' , '<STR_LIT>' , freq = '<STR_LIT:M>' ) <EOL> self . assertEqual ( dr [ <NUM_LIT:0> ] , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> self . assertEqual ( dr [ - <NUM_LIT:1> ] , datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> ) ) <EOL> def test_freq_divides_end_in_nanos ( self ) : <EOL> result_1 = date_range ( '<STR_LIT>' , '<STR_LIT>' , <EOL> freq = '<STR_LIT>' ) <EOL> result_2 = date_range ( '<STR_LIT>' , '<STR_LIT>' , <EOL> freq = '<STR_LIT>' ) <EOL> expected_1 = DatetimeIndex ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> dtype = '<STR_LIT>' , freq = '<STR_LIT>' , <EOL> tz = None ) <EOL> expected_2 = DatetimeIndex ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> dtype = '<STR_LIT>' , freq = '<STR_LIT>' , <EOL> tz = None ) <EOL> self . assertTrue ( result_1 . equals ( expected_1 ) ) <EOL> self . assertTrue ( result_2 . equals ( expected_2 ) ) <EOL> class TestCustomDateRange ( tm . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . rng = cdate_range ( START , END ) <EOL> def test_constructor ( self ) : <EOL> cdate_range ( START , END , freq = datetools . cday ) <EOL> cdate_range ( START , periods = <NUM_LIT:20> , freq = datetools . cday ) <EOL> cdate_range ( end = START , periods = <NUM_LIT:20> , freq = datetools . cday ) <EOL> self . assertRaises ( ValueError , date_range , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:C>' ) <EOL> self . assertRaises ( ValueError , cdate_range , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:C>' ) <EOL> def test_cached_range ( self ) : <EOL> DatetimeIndex . _cached_range ( START , END , offset = datetools . cday ) <EOL> DatetimeIndex . _cached_range ( START , periods = <NUM_LIT:20> , <EOL> offset = datetools . cday ) <EOL> DatetimeIndex . _cached_range ( end = START , periods = <NUM_LIT:20> , <EOL> offset = datetools . cday ) <EOL> self . assertRaises ( Exception , DatetimeIndex . _cached_range , START , END ) <EOL> self . assertRaises ( Exception , DatetimeIndex . _cached_range , START , <EOL> freq = datetools . cday ) <EOL> self . assertRaises ( Exception , DatetimeIndex . _cached_range , end = END , <EOL> freq = datetools . cday ) <EOL> self . assertRaises ( Exception , DatetimeIndex . _cached_range , periods = <NUM_LIT:20> , <EOL> freq = datetools . cday ) <EOL> def test_comparison ( self ) : <EOL> d = self . rng [ <NUM_LIT:10> ] <EOL> comp = self . rng > d <EOL> self . assertTrue ( comp [ <NUM_LIT:11> ] ) <EOL> self . assertFalse ( comp [ <NUM_LIT:9> ] ) <EOL> def test_copy ( self ) : <EOL> cp = self . rng . copy ( ) <EOL> repr ( cp ) <EOL> self . assertTrue ( cp . equals ( self . rng ) ) <EOL> def test_repr ( self ) : <EOL> repr ( self . rng ) <EOL> def test_getitem ( self ) : <EOL> smaller = self . rng [ : <NUM_LIT:5> ] <EOL> self . assert_numpy_array_equal ( smaller , self . rng . view ( np . ndarray ) [ : <NUM_LIT:5> ] ) <EOL> self . assertEqual ( smaller . offset , self . rng . offset ) <EOL> sliced = self . rng [ : : <NUM_LIT:5> ] <EOL> self . assertEqual ( sliced . offset , datetools . cday * <NUM_LIT:5> ) <EOL> fancy_indexed = self . rng [ [ <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] ] <EOL> self . assertEqual ( len ( fancy_indexed ) , <NUM_LIT:5> ) <EOL> tm . assertIsInstance ( fancy_indexed , DatetimeIndex ) <EOL> self . assertIsNone ( fancy_indexed . freq ) <EOL> self . assertEqual ( self . rng [ <NUM_LIT:4> ] , self . rng [ np . int_ ( <NUM_LIT:4> ) ] ) <EOL> def test_getitem_matplotlib_hackaround ( self ) : <EOL> values = self . rng [ : , None ] <EOL> expected = self . rng . values [ : , None ] <EOL> self . assert_numpy_array_equal ( values , expected ) <EOL> def test_shift ( self ) : <EOL> shifted = self . rng . shift ( <NUM_LIT:5> ) <EOL> self . assertEqual ( shifted [ <NUM_LIT:0> ] , self . rng [ <NUM_LIT:5> ] ) <EOL> self . assertEqual ( shifted . offset , self . rng . offset ) <EOL> shifted = self . rng . shift ( - <NUM_LIT:5> ) <EOL> self . assertEqual ( shifted [ <NUM_LIT:5> ] , self . rng [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( shifted . offset , self . rng . offset ) <EOL> shifted = self . rng . shift ( <NUM_LIT:0> ) <EOL> self . assertEqual ( shifted [ <NUM_LIT:0> ] , self . rng [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( shifted . offset , self . rng . offset ) <EOL> with tm . assert_produces_warning ( com . PerformanceWarning ) : <EOL> rng = date_range ( START , END , freq = datetools . bmonthEnd ) <EOL> shifted = rng . shift ( <NUM_LIT:1> , freq = datetools . cday ) <EOL> self . assertEqual ( shifted [ <NUM_LIT:0> ] , rng [ <NUM_LIT:0> ] + datetools . cday ) <EOL> def test_pickle_unpickle ( self ) : <EOL> unpickled = self . round_trip_pickle ( self . rng ) <EOL> self . assertIsNotNone ( unpickled . offset ) <EOL> def test_union ( self ) : <EOL> left = self . rng [ : <NUM_LIT:10> ] <EOL> right = self . rng [ <NUM_LIT:5> : <NUM_LIT:10> ] <EOL> the_union = left . union ( right ) <EOL> tm . assertIsInstance ( the_union , DatetimeIndex ) <EOL> left = self . rng [ : <NUM_LIT:5> ] <EOL> right = self . rng [ <NUM_LIT:10> : ] <EOL> the_union = left . union ( right ) <EOL> tm . assertIsInstance ( the_union , Index ) <EOL> left = self . rng [ : <NUM_LIT:5> ] <EOL> right = self . rng [ <NUM_LIT:5> : <NUM_LIT:10> ] <EOL> the_union = left . union ( right ) <EOL> tm . assertIsInstance ( the_union , DatetimeIndex ) <EOL> self . assert_numpy_array_equal ( right . union ( left ) , the_union ) <EOL> rng = date_range ( START , END , freq = datetools . bmonthEnd ) <EOL> the_union = self . rng . union ( rng ) <EOL> tm . assertIsInstance ( the_union , DatetimeIndex ) <EOL> def test_outer_join ( self ) : <EOL> left = self . rng [ : <NUM_LIT:10> ] <EOL> right = self . rng [ <NUM_LIT:5> : <NUM_LIT:10> ] <EOL> the_join = left . join ( right , how = '<STR_LIT>' ) <EOL> tm . assertIsInstance ( the_join , DatetimeIndex ) <EOL> left = self . rng [ : <NUM_LIT:5> ] <EOL> right = self . rng [ <NUM_LIT:10> : ] <EOL> the_join = left . join ( right , how = '<STR_LIT>' ) <EOL> tm . assertIsInstance ( the_join , DatetimeIndex ) <EOL> self . assertIsNone ( the_join . freq ) <EOL> left = self . rng [ : <NUM_LIT:5> ] <EOL> right = self . rng [ <NUM_LIT:5> : <NUM_LIT:10> ] <EOL> the_join = left . join ( right , how = '<STR_LIT>' ) <EOL> tm . assertIsInstance ( the_join , DatetimeIndex ) <EOL> rng = date_range ( START , END , freq = datetools . bmonthEnd ) <EOL> the_join = self . rng . join ( rng , how = '<STR_LIT>' ) <EOL> tm . assertIsInstance ( the_join , DatetimeIndex ) <EOL> self . assertIsNone ( the_join . freq ) <EOL> def test_intersection_bug ( self ) : <EOL> a = cdate_range ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> b = cdate_range ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> result = a . intersection ( b ) <EOL> self . assertTrue ( result . equals ( b ) ) <EOL> def test_summary ( self ) : <EOL> self . rng . summary ( ) <EOL> self . rng [ <NUM_LIT:2> : <NUM_LIT:2> ] . summary ( ) <EOL> def test_summary_pytz ( self ) : <EOL> tm . _skip_if_no_pytz ( ) <EOL> import pytz <EOL> cdate_range ( '<STR_LIT>' , '<STR_LIT>' , tz = pytz . utc ) . summary ( ) <EOL> def test_summary_dateutil ( self ) : <EOL> tm . _skip_if_no_dateutil ( ) <EOL> import dateutil <EOL> cdate_range ( '<STR_LIT>' , '<STR_LIT>' , tz = dateutil . tz . tzutc ( ) ) . summary ( ) <EOL> def test_misc ( self ) : <EOL> end = datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> ) <EOL> dr = cdate_range ( end = end , periods = <NUM_LIT:20> ) <EOL> firstDate = end - <NUM_LIT> * datetools . cday <EOL> assert len ( dr ) == <NUM_LIT:20> <EOL> assert dr [ <NUM_LIT:0> ] == firstDate <EOL> assert dr [ - <NUM_LIT:1> ] == end <EOL> def test_date_parse_failure ( self ) : <EOL> badly_formed_date = '<STR_LIT>' <EOL> self . assertRaises ( ValueError , Timestamp , badly_formed_date ) <EOL> self . assertRaises ( ValueError , cdate_range , start = badly_formed_date , <EOL> periods = <NUM_LIT:10> ) <EOL> self . assertRaises ( ValueError , cdate_range , end = badly_formed_date , <EOL> periods = <NUM_LIT:10> ) <EOL> self . assertRaises ( ValueError , cdate_range , badly_formed_date , <EOL> badly_formed_date ) <EOL> def test_equals ( self ) : <EOL> self . assertFalse ( self . rng . equals ( list ( self . rng ) ) ) <EOL> def test_daterange_bug_456 ( self ) : <EOL> rng1 = cdate_range ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> rng2 = cdate_range ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> rng2 . offset = datetools . CDay ( ) <EOL> result = rng1 . union ( rng2 ) <EOL> tm . assertIsInstance ( result , DatetimeIndex ) <EOL> def test_cdaterange ( self ) : <EOL> rng = cdate_range ( '<STR_LIT>' , periods = <NUM_LIT:3> ) <EOL> xp = DatetimeIndex ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( xp . equals ( rng ) ) <EOL> def test_cdaterange_weekmask ( self ) : <EOL> rng = cdate_range ( '<STR_LIT>' , periods = <NUM_LIT:3> , <EOL> weekmask = '<STR_LIT>' ) <EOL> xp = DatetimeIndex ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( xp . equals ( rng ) ) <EOL> def test_cdaterange_holidays ( self ) : <EOL> rng = cdate_range ( '<STR_LIT>' , periods = <NUM_LIT:3> , holidays = [ '<STR_LIT>' ] ) <EOL> xp = DatetimeIndex ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( xp . equals ( rng ) ) <EOL> def test_cdaterange_weekmask_and_holidays ( self ) : <EOL> rng = cdate_range ( '<STR_LIT>' , periods = <NUM_LIT:3> , <EOL> weekmask = '<STR_LIT>' , <EOL> holidays = [ '<STR_LIT>' ] ) <EOL> xp = DatetimeIndex ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( xp . equals ( rng ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> nose . runmodule ( argv = [ __file__ , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> exit = False ) </s>
