<s> from datetime import datetime <EOL> import sys <EOL> import os <EOL> import nose <EOL> import numpy as np <EOL> from pandas import ( Index , Series , date_range , Timestamp , <EOL> DatetimeIndex , Int64Index , to_datetime ) <EOL> import pandas . core . datetools as datetools <EOL> import pandas . tseries . offsets as offsets <EOL> import pandas as pd <EOL> from pandas . util . testing import assert_series_equal , assert_almost_equal <EOL> import pandas . util . testing as tm <EOL> from pandas . compat import StringIO , cPickle as pickle <EOL> from pandas import read_pickle <EOL> from numpy . random import rand <EOL> import pandas . compat as compat <EOL> from pandas . core . datetools import BDay <EOL> randn = np . random . randn <EOL> class LegacySupport ( object ) : <EOL> _multiprocess_can_split_ = True <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> if compat . PY3 : <EOL> raise nose . SkipTest ( "<STR_LIT>" ) <EOL> pth , _ = os . path . split ( os . path . abspath ( __file__ ) ) <EOL> filepath = os . path . join ( pth , '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> with open ( filepath , '<STR_LIT:rb>' ) as f : <EOL> cls . frame = pickle . load ( f ) <EOL> filepath = os . path . join ( pth , '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> with open ( filepath , '<STR_LIT:rb>' ) as f : <EOL> cls . series = pickle . load ( f ) <EOL> def test_pass_offset_warn ( self ) : <EOL> buf = StringIO ( ) <EOL> sys . stderr = buf <EOL> DatetimeIndex ( start = '<STR_LIT>' , periods = <NUM_LIT:10> , offset = '<STR_LIT:H>' ) <EOL> sys . stderr = sys . __stderr__ <EOL> def test_unpickle_legacy_frame ( self ) : <EOL> dtindex = DatetimeIndex ( start = '<STR_LIT>' , end = '<STR_LIT>' , <EOL> freq = BDay ( <NUM_LIT:1> ) ) <EOL> unpickled = self . frame <EOL> self . assertEqual ( type ( unpickled . index ) , DatetimeIndex ) <EOL> self . assertEqual ( len ( unpickled ) , <NUM_LIT:10> ) <EOL> self . assertTrue ( ( unpickled . columns == Int64Index ( np . arange ( <NUM_LIT:5> ) ) ) . all ( ) ) <EOL> self . assertTrue ( ( unpickled . index == dtindex ) . all ( ) ) <EOL> self . assertEqual ( unpickled . index . offset , BDay ( <NUM_LIT:1> , normalize = True ) ) <EOL> def test_unpickle_legacy_series ( self ) : <EOL> from pandas . core . datetools import BDay <EOL> unpickled = self . series <EOL> dtindex = DatetimeIndex ( start = '<STR_LIT>' , end = '<STR_LIT>' , <EOL> freq = BDay ( <NUM_LIT:1> ) ) <EOL> self . assertEqual ( type ( unpickled . index ) , DatetimeIndex ) <EOL> self . assertEqual ( len ( unpickled ) , <NUM_LIT:10> ) <EOL> self . assertTrue ( ( unpickled . index == dtindex ) . all ( ) ) <EOL> self . assertEqual ( unpickled . index . offset , BDay ( <NUM_LIT:1> , normalize = True ) ) <EOL> def test_unpickle_legacy_len0_daterange ( self ) : <EOL> pth , _ = os . path . split ( os . path . abspath ( __file__ ) ) <EOL> filepath = os . path . join ( pth , '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> result = pd . read_pickle ( filepath ) <EOL> ex_index = DatetimeIndex ( [ ] , freq = '<STR_LIT:B>' ) <EOL> self . assertTrue ( result . index . equals ( ex_index ) ) <EOL> tm . assertIsInstance ( result . index . freq , offsets . BDay ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:0> ) <EOL> def test_arithmetic_interaction ( self ) : <EOL> index = self . frame . index <EOL> obj_index = index . asobject <EOL> dseries = Series ( rand ( len ( index ) ) , index = index ) <EOL> oseries = Series ( dseries . values , index = obj_index ) <EOL> result = dseries + oseries <EOL> expected = dseries * <NUM_LIT:2> <EOL> tm . assertIsInstance ( result . index , DatetimeIndex ) <EOL> assert_series_equal ( result , expected ) <EOL> result = dseries + oseries [ : <NUM_LIT:5> ] <EOL> expected = dseries + dseries [ : <NUM_LIT:5> ] <EOL> tm . assertIsInstance ( result . index , DatetimeIndex ) <EOL> assert_series_equal ( result , expected ) <EOL> def test_join_interaction ( self ) : <EOL> index = self . frame . index <EOL> obj_index = index . asobject <EOL> def _check_join ( left , right , how = '<STR_LIT>' ) : <EOL> ra , rb , rc = left . join ( right , how = how , return_indexers = True ) <EOL> ea , eb , ec = left . join ( DatetimeIndex ( right ) , how = how , <EOL> return_indexers = True ) <EOL> tm . assertIsInstance ( ra , DatetimeIndex ) <EOL> self . assertTrue ( ra . equals ( ea ) ) <EOL> assert_almost_equal ( rb , eb ) <EOL> assert_almost_equal ( rc , ec ) <EOL> _check_join ( index [ : <NUM_LIT:15> ] , obj_index [ <NUM_LIT:5> : ] , how = '<STR_LIT>' ) <EOL> _check_join ( index [ : <NUM_LIT:15> ] , obj_index [ <NUM_LIT:5> : ] , how = '<STR_LIT>' ) <EOL> _check_join ( index [ : <NUM_LIT:15> ] , obj_index [ <NUM_LIT:5> : ] , how = '<STR_LIT:right>' ) <EOL> _check_join ( index [ : <NUM_LIT:15> ] , obj_index [ <NUM_LIT:5> : ] , how = '<STR_LIT:left>' ) <EOL> def test_join_nonunique ( self ) : <EOL> idx1 = to_datetime ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> idx2 = to_datetime ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> rs = idx1 . join ( idx2 , how = '<STR_LIT>' ) <EOL> self . assertTrue ( rs . is_monotonic ) <EOL> def test_unpickle_daterange ( self ) : <EOL> pth , _ = os . path . split ( os . path . abspath ( __file__ ) ) <EOL> filepath = os . path . join ( pth , '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> rng = read_pickle ( filepath ) <EOL> tm . assertIsInstance ( rng [ <NUM_LIT:0> ] , datetime ) <EOL> tm . assertIsInstance ( rng . offset , offsets . BDay ) <EOL> self . assertEqual ( rng . values . dtype , object ) <EOL> def test_setops ( self ) : <EOL> index = self . frame . index <EOL> obj_index = index . asobject <EOL> result = index [ : <NUM_LIT:5> ] . union ( obj_index [ <NUM_LIT:5> : ] ) <EOL> expected = index <EOL> tm . assertIsInstance ( result , DatetimeIndex ) <EOL> self . assertTrue ( result . equals ( expected ) ) <EOL> result = index [ : <NUM_LIT:10> ] . intersection ( obj_index [ <NUM_LIT:5> : ] ) <EOL> expected = index [ <NUM_LIT:5> : <NUM_LIT:10> ] <EOL> tm . assertIsInstance ( result , DatetimeIndex ) <EOL> self . assertTrue ( result . equals ( expected ) ) <EOL> result = index [ : <NUM_LIT:10> ] - obj_index [ <NUM_LIT:5> : ] <EOL> expected = index [ : <NUM_LIT:5> ] <EOL> tm . assertIsInstance ( result , DatetimeIndex ) <EOL> self . assertTrue ( result . equals ( expected ) ) <EOL> def test_index_conversion ( self ) : <EOL> index = self . frame . index <EOL> obj_index = index . asobject <EOL> conv = DatetimeIndex ( obj_index ) <EOL> self . assertTrue ( conv . equals ( index ) ) <EOL> self . assertRaises ( ValueError , DatetimeIndex , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] ) <EOL> def test_tolist ( self ) : <EOL> rng = date_range ( '<STR_LIT>' , periods = <NUM_LIT:10> ) <EOL> result = rng . tolist ( ) <EOL> tm . assertIsInstance ( result [ <NUM_LIT:0> ] , Timestamp ) <EOL> def test_object_convert_fail ( self ) : <EOL> idx = DatetimeIndex ( [ np . NaT ] ) <EOL> self . assertRaises ( ValueError , idx . astype , '<STR_LIT:O>' ) <EOL> def test_setops_conversion_fail ( self ) : <EOL> index = self . frame . index <EOL> right = Index ( [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] ) <EOL> result = index . union ( right ) <EOL> expected = Index ( np . concatenate ( [ index . asobject , right ] ) ) <EOL> self . assertTrue ( result . equals ( expected ) ) <EOL> result = index . intersection ( right ) <EOL> expected = Index ( [ ] ) <EOL> self . assertTrue ( result . equals ( expected ) ) <EOL> def test_legacy_time_rules ( self ) : <EOL> rules = [ ( '<STR_LIT>' , '<STR_LIT:B>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> start , end = '<STR_LIT>' , '<STR_LIT>' <EOL> for old_freq , new_freq in rules : <EOL> old_rng = date_range ( start , end , freq = old_freq ) <EOL> new_rng = date_range ( start , end , freq = new_freq ) <EOL> self . assertTrue ( old_rng . equals ( new_rng ) ) <EOL> offset = datetools . get_offset ( new_freq ) <EOL> old_name = datetools . get_legacy_offset_name ( offset ) <EOL> self . assertEqual ( old_name , old_freq ) <EOL> def test_ms_vs_MS ( self ) : <EOL> left = datetools . get_offset ( '<STR_LIT>' ) <EOL> right = datetools . get_offset ( '<STR_LIT>' ) <EOL> self . assertEqual ( left , datetools . Milli ( ) ) <EOL> self . assertEqual ( right , datetools . MonthBegin ( ) ) <EOL> def test_rule_aliases ( self ) : <EOL> rule = datetools . to_offset ( '<STR_LIT>' ) <EOL> self . assertEqual ( rule , datetools . Micro ( <NUM_LIT:10> ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> nose . runmodule ( argv = [ __file__ , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> exit = False ) </s>
