<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from pandas . core . base import PandasDelegate , NoNewAttributesMixin <EOL> from pandas . core import common as com <EOL> from pandas . tseries . index import DatetimeIndex <EOL> from pandas . _period import IncompatibleFrequency <EOL> from pandas . tseries . period import PeriodIndex <EOL> from pandas . tseries . tdi import TimedeltaIndex <EOL> from pandas import tslib <EOL> from pandas . core . algorithms import take_1d <EOL> from pandas . core . common import ( _NS_DTYPE , _TD_DTYPE , is_period_arraylike , <EOL> is_datetime_arraylike , is_integer_dtype , <EOL> is_list_like , <EOL> is_datetime64_dtype , is_datetime64tz_dtype , <EOL> is_timedelta64_dtype , is_categorical_dtype ) <EOL> def is_datetimelike ( data ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> maybe_to_datetimelike ( data ) <EOL> return True <EOL> except ( Exception ) : <EOL> pass <EOL> return False <EOL> def maybe_to_datetimelike ( data , copy = False ) : <EOL> """<STR_LIT>""" <EOL> from pandas import Series <EOL> if not isinstance ( data , Series ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( type ( data ) ) ) <EOL> index = data . index <EOL> name = data . name <EOL> orig = data if is_categorical_dtype ( data ) else None <EOL> if orig is not None : <EOL> data = orig . values . categories <EOL> if is_datetime64_dtype ( data . dtype ) : <EOL> return DatetimeProperties ( DatetimeIndex ( data , copy = copy , freq = '<STR_LIT>' ) , <EOL> index , name = name , orig = orig ) <EOL> elif is_datetime64tz_dtype ( data . dtype ) : <EOL> return DatetimeProperties ( DatetimeIndex ( data , copy = copy , freq = '<STR_LIT>' , <EOL> ambiguous = '<STR_LIT>' ) , <EOL> index , data . name , orig = orig ) <EOL> elif is_timedelta64_dtype ( data . dtype ) : <EOL> return TimedeltaProperties ( TimedeltaIndex ( data , copy = copy , <EOL> freq = '<STR_LIT>' ) , index , <EOL> name = name , orig = orig ) <EOL> else : <EOL> if is_period_arraylike ( data ) : <EOL> return PeriodProperties ( PeriodIndex ( data , copy = copy ) , index , <EOL> name = name , orig = orig ) <EOL> if is_datetime_arraylike ( data ) : <EOL> return DatetimeProperties ( DatetimeIndex ( data , copy = copy , <EOL> freq = '<STR_LIT>' ) , index , <EOL> name = name , orig = orig ) <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( type ( data ) ) ) <EOL> class Properties ( PandasDelegate , NoNewAttributesMixin ) : <EOL> def __init__ ( self , values , index , name , orig = None ) : <EOL> self . values = values <EOL> self . index = index <EOL> self . name = name <EOL> self . orig = orig <EOL> self . _freeze ( ) <EOL> def _delegate_property_get ( self , name ) : <EOL> from pandas import Series <EOL> result = getattr ( self . values , name ) <EOL> if isinstance ( result , np . ndarray ) : <EOL> if is_integer_dtype ( result ) : <EOL> result = result . astype ( '<STR_LIT>' ) <EOL> elif not is_list_like ( result ) : <EOL> return result <EOL> if self . orig is not None : <EOL> result = take_1d ( result , self . orig . cat . codes ) <EOL> result = Series ( result , index = self . index , name = self . name ) <EOL> result . is_copy = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return result <EOL> def _delegate_property_set ( self , name , value , * args , ** kwargs ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def _delegate_method ( self , name , * args , ** kwargs ) : <EOL> from pandas import Series <EOL> method = getattr ( self . values , name ) <EOL> result = method ( * args , ** kwargs ) <EOL> if not com . is_list_like ( result ) : <EOL> return result <EOL> result = Series ( result , index = self . index , name = self . name ) <EOL> result . is_copy = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return result <EOL> class DatetimeProperties ( Properties ) : <EOL> """<STR_LIT>""" <EOL> def to_pydatetime ( self ) : <EOL> return self . values . to_pydatetime ( ) <EOL> DatetimeProperties . _add_delegate_accessors ( <EOL> delegate = DatetimeIndex , <EOL> accessors = DatetimeIndex . _datetimelike_ops , <EOL> typ = '<STR_LIT>' ) <EOL> DatetimeProperties . _add_delegate_accessors ( <EOL> delegate = DatetimeIndex , <EOL> accessors = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> typ = '<STR_LIT>' ) <EOL> class TimedeltaProperties ( Properties ) : <EOL> """<STR_LIT>""" <EOL> def to_pytimedelta ( self ) : <EOL> return self . values . to_pytimedelta ( ) <EOL> @ property <EOL> def components ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . values . components . set_index ( self . index ) <EOL> TimedeltaProperties . _add_delegate_accessors ( <EOL> delegate = TimedeltaIndex , <EOL> accessors = TimedeltaIndex . _datetimelike_ops , <EOL> typ = '<STR_LIT>' ) <EOL> TimedeltaProperties . _add_delegate_accessors ( <EOL> delegate = TimedeltaIndex , <EOL> accessors = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> typ = '<STR_LIT>' ) <EOL> class PeriodProperties ( Properties ) : <EOL> """<STR_LIT>""" <EOL> PeriodProperties . _add_delegate_accessors ( <EOL> delegate = PeriodIndex , <EOL> accessors = PeriodIndex . _datetimelike_ops , <EOL> typ = '<STR_LIT>' ) <EOL> PeriodProperties . _add_delegate_accessors ( delegate = PeriodIndex , <EOL> accessors = [ "<STR_LIT>" ] , <EOL> typ = '<STR_LIT>' ) <EOL> class CombinedDatetimelikeProperties ( DatetimeProperties , TimedeltaProperties ) : <EOL> __doc__ = DatetimeProperties . __doc__ </s>
