<s> from itertools import product <EOL> import nose <EOL> import numpy as np <EOL> from pandas import Series , Categorical , date_range <EOL> import pandas . core . common as com <EOL> from pandas . types . api import CategoricalDtype <EOL> from pandas . core . common import ( is_categorical_dtype , <EOL> is_categorical , DatetimeTZDtype , <EOL> is_datetime64tz_dtype , is_datetimetz , <EOL> is_dtype_equal , is_datetime64_ns_dtype , <EOL> is_datetime64_dtype ) <EOL> import pandas . util . testing as tm <EOL> _multiprocess_can_split_ = True <EOL> class Base ( object ) : <EOL> def test_hash ( self ) : <EOL> hash ( self . dtype ) <EOL> def test_equality_invalid ( self ) : <EOL> self . assertRaises ( self . dtype == '<STR_LIT:foo>' ) <EOL> def test_numpy_informed ( self ) : <EOL> def f ( ) : <EOL> np . dtype ( self . dtype ) <EOL> self . assertRaises ( TypeError , f ) <EOL> self . assertNotEqual ( self . dtype , np . str_ ) <EOL> self . assertNotEqual ( np . str_ , self . dtype ) <EOL> def test_pickle ( self ) : <EOL> result = self . round_trip_pickle ( self . dtype ) <EOL> self . assertEqual ( result , self . dtype ) <EOL> class TestCategoricalDtype ( Base , tm . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . dtype = CategoricalDtype ( ) <EOL> def test_equality ( self ) : <EOL> self . assertTrue ( is_dtype_equal ( self . dtype , '<STR_LIT>' ) ) <EOL> self . assertTrue ( is_dtype_equal ( self . dtype , CategoricalDtype ( ) ) ) <EOL> self . assertFalse ( is_dtype_equal ( self . dtype , '<STR_LIT:foo>' ) ) <EOL> def test_construction_from_string ( self ) : <EOL> result = CategoricalDtype . construct_from_string ( '<STR_LIT>' ) <EOL> self . assertTrue ( is_dtype_equal ( self . dtype , result ) ) <EOL> self . assertRaises ( <EOL> TypeError , lambda : CategoricalDtype . construct_from_string ( '<STR_LIT:foo>' ) ) <EOL> def test_is_dtype ( self ) : <EOL> self . assertTrue ( CategoricalDtype . is_dtype ( self . dtype ) ) <EOL> self . assertTrue ( CategoricalDtype . is_dtype ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( CategoricalDtype . is_dtype ( CategoricalDtype ( ) ) ) <EOL> self . assertFalse ( CategoricalDtype . is_dtype ( '<STR_LIT:foo>' ) ) <EOL> self . assertFalse ( CategoricalDtype . is_dtype ( np . float64 ) ) <EOL> def test_basic ( self ) : <EOL> self . assertTrue ( is_categorical_dtype ( self . dtype ) ) <EOL> factor = Categorical . from_array ( [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:b>' , '<STR_LIT:a>' , '<STR_LIT:a>' , '<STR_LIT:c>' , '<STR_LIT:c>' , '<STR_LIT:c>' <EOL> ] ) <EOL> s = Series ( factor , name = '<STR_LIT:A>' ) <EOL> self . assertTrue ( is_categorical_dtype ( s . dtype ) ) <EOL> self . assertTrue ( is_categorical_dtype ( s ) ) <EOL> self . assertFalse ( is_categorical_dtype ( np . dtype ( '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( is_categorical ( s . dtype ) ) <EOL> self . assertTrue ( is_categorical ( s ) ) <EOL> self . assertFalse ( is_categorical ( np . dtype ( '<STR_LIT>' ) ) ) <EOL> self . assertFalse ( is_categorical ( <NUM_LIT:1.0> ) ) <EOL> class TestDatetimeTZDtype ( Base , tm . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . dtype = DatetimeTZDtype ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_construction ( self ) : <EOL> self . assertRaises ( ValueError , <EOL> lambda : DatetimeTZDtype ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_subclass ( self ) : <EOL> a = DatetimeTZDtype ( '<STR_LIT>' ) <EOL> b = DatetimeTZDtype ( '<STR_LIT>' ) <EOL> self . assertTrue ( issubclass ( type ( a ) , type ( a ) ) ) <EOL> self . assertTrue ( issubclass ( type ( a ) , type ( b ) ) ) <EOL> def test_coerce_to_dtype ( self ) : <EOL> self . assertEqual ( com . _coerce_to_dtype ( '<STR_LIT>' ) , <EOL> DatetimeTZDtype ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( com . _coerce_to_dtype ( '<STR_LIT>' ) , <EOL> DatetimeTZDtype ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_compat ( self ) : <EOL> self . assertFalse ( is_datetime64_ns_dtype ( self . dtype ) ) <EOL> self . assertFalse ( is_datetime64_ns_dtype ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( is_datetime64_dtype ( self . dtype ) ) <EOL> self . assertFalse ( is_datetime64_dtype ( '<STR_LIT>' ) ) <EOL> def test_construction_from_string ( self ) : <EOL> result = DatetimeTZDtype ( '<STR_LIT>' ) <EOL> self . assertTrue ( is_dtype_equal ( self . dtype , result ) ) <EOL> result = DatetimeTZDtype . construct_from_string ( <EOL> '<STR_LIT>' ) <EOL> self . assertTrue ( is_dtype_equal ( self . dtype , result ) ) <EOL> self . assertRaises ( TypeError , <EOL> lambda : DatetimeTZDtype . construct_from_string ( '<STR_LIT:foo>' ) ) <EOL> def test_is_dtype ( self ) : <EOL> self . assertTrue ( DatetimeTZDtype . is_dtype ( self . dtype ) ) <EOL> self . assertTrue ( DatetimeTZDtype . is_dtype ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( DatetimeTZDtype . is_dtype ( '<STR_LIT:foo>' ) ) <EOL> self . assertTrue ( DatetimeTZDtype . is_dtype ( DatetimeTZDtype ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> self . assertFalse ( DatetimeTZDtype . is_dtype ( np . float64 ) ) <EOL> def test_equality ( self ) : <EOL> self . assertTrue ( is_dtype_equal ( self . dtype , <EOL> '<STR_LIT>' ) ) <EOL> self . assertTrue ( is_dtype_equal ( self . dtype , DatetimeTZDtype ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> self . assertFalse ( is_dtype_equal ( self . dtype , '<STR_LIT:foo>' ) ) <EOL> self . assertFalse ( is_dtype_equal ( self . dtype , DatetimeTZDtype ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) ) <EOL> self . assertFalse ( is_dtype_equal ( <EOL> DatetimeTZDtype ( '<STR_LIT>' , '<STR_LIT>' ) , DatetimeTZDtype ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( is_dtype_equal ( np . dtype ( "<STR_LIT>" ) , "<STR_LIT>" ) ) <EOL> def test_basic ( self ) : <EOL> self . assertTrue ( is_datetime64tz_dtype ( self . dtype ) ) <EOL> dr = date_range ( '<STR_LIT>' , periods = <NUM_LIT:3> , tz = '<STR_LIT>' ) <EOL> s = Series ( dr , name = '<STR_LIT:A>' ) <EOL> self . assertTrue ( is_datetime64tz_dtype ( s . dtype ) ) <EOL> self . assertTrue ( is_datetime64tz_dtype ( s ) ) <EOL> self . assertFalse ( is_datetime64tz_dtype ( np . dtype ( '<STR_LIT>' ) ) ) <EOL> self . assertFalse ( is_datetime64tz_dtype ( <NUM_LIT:1.0> ) ) <EOL> self . assertTrue ( is_datetimetz ( s ) ) <EOL> self . assertTrue ( is_datetimetz ( s . dtype ) ) <EOL> self . assertFalse ( is_datetimetz ( np . dtype ( '<STR_LIT>' ) ) ) <EOL> self . assertFalse ( is_datetimetz ( <NUM_LIT:1.0> ) ) <EOL> def test_dst ( self ) : <EOL> dr1 = date_range ( '<STR_LIT>' , periods = <NUM_LIT:3> , tz = '<STR_LIT>' ) <EOL> s1 = Series ( dr1 , name = '<STR_LIT:A>' ) <EOL> self . assertTrue ( is_datetimetz ( s1 ) ) <EOL> dr2 = date_range ( '<STR_LIT>' , periods = <NUM_LIT:3> , tz = '<STR_LIT>' ) <EOL> s2 = Series ( dr2 , name = '<STR_LIT:A>' ) <EOL> self . assertTrue ( is_datetimetz ( s2 ) ) <EOL> self . assertEqual ( s1 . dtype , s2 . dtype ) <EOL> def test_parser ( self ) : <EOL> for tz , constructor in product ( ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> self . assertEqual ( <EOL> DatetimeTZDtype ( '<STR_LIT>' % ( constructor , tz ) ) , <EOL> DatetimeTZDtype ( '<STR_LIT>' , tz ) , <EOL> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> nose . runmodule ( argv = [ __file__ , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> exit = False ) </s>
