<s> from __future__ import print_function <EOL> from datetime import timedelta <EOL> import numpy as np <EOL> from pandas import ( DataFrame , Series , date_range , Timedelta , Timestamp , <EOL> compat , option_context ) <EOL> from pandas . compat import u <EOL> from pandas . tests . frame . common import TestData <EOL> from pandas . util . testing import ( assert_series_equal , <EOL> assert_frame_equal , <EOL> makeCustomDataframe as mkdf ) <EOL> import pandas . util . testing as tm <EOL> import pandas as pd <EOL> class TestDataFrameDataTypes ( tm . TestCase , TestData ) : <EOL> _multiprocess_can_split_ = True <EOL> def test_concat_empty_dataframe_dtypes ( self ) : <EOL> df = DataFrame ( columns = list ( "<STR_LIT:abc>" ) ) <EOL> df [ '<STR_LIT:a>' ] = df [ '<STR_LIT:a>' ] . astype ( np . bool_ ) <EOL> df [ '<STR_LIT:b>' ] = df [ '<STR_LIT:b>' ] . astype ( np . int32 ) <EOL> df [ '<STR_LIT:c>' ] = df [ '<STR_LIT:c>' ] . astype ( np . float64 ) <EOL> result = pd . concat ( [ df , df ] ) <EOL> self . assertEqual ( result [ '<STR_LIT:a>' ] . dtype , np . bool_ ) <EOL> self . assertEqual ( result [ '<STR_LIT:b>' ] . dtype , np . int32 ) <EOL> self . assertEqual ( result [ '<STR_LIT:c>' ] . dtype , np . float64 ) <EOL> result = pd . concat ( [ df , df . astype ( np . float64 ) ] ) <EOL> self . assertEqual ( result [ '<STR_LIT:a>' ] . dtype , np . object_ ) <EOL> self . assertEqual ( result [ '<STR_LIT:b>' ] . dtype , np . float64 ) <EOL> self . assertEqual ( result [ '<STR_LIT:c>' ] . dtype , np . float64 ) <EOL> def test_empty_frame_dtypes_ftypes ( self ) : <EOL> empty_df = pd . DataFrame ( ) <EOL> assert_series_equal ( empty_df . dtypes , pd . Series ( dtype = np . object ) ) <EOL> assert_series_equal ( empty_df . ftypes , pd . Series ( dtype = np . object ) ) <EOL> nocols_df = pd . DataFrame ( index = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> assert_series_equal ( nocols_df . dtypes , pd . Series ( dtype = np . object ) ) <EOL> assert_series_equal ( nocols_df . ftypes , pd . Series ( dtype = np . object ) ) <EOL> norows_df = pd . DataFrame ( columns = list ( "<STR_LIT:abc>" ) ) <EOL> assert_series_equal ( norows_df . dtypes , pd . Series ( <EOL> np . object , index = list ( "<STR_LIT:abc>" ) ) ) <EOL> assert_series_equal ( norows_df . ftypes , pd . Series ( <EOL> '<STR_LIT>' , index = list ( "<STR_LIT:abc>" ) ) ) <EOL> norows_int_df = pd . DataFrame ( columns = list ( "<STR_LIT:abc>" ) ) . astype ( np . int32 ) <EOL> assert_series_equal ( norows_int_df . dtypes , pd . Series ( <EOL> np . dtype ( '<STR_LIT>' ) , index = list ( "<STR_LIT:abc>" ) ) ) <EOL> assert_series_equal ( norows_int_df . ftypes , pd . Series ( <EOL> '<STR_LIT>' , index = list ( "<STR_LIT:abc>" ) ) ) <EOL> odict = compat . OrderedDict <EOL> df = pd . DataFrame ( odict ( [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , True ) , ( '<STR_LIT:c>' , <NUM_LIT:1.0> ) ] ) , <EOL> index = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> ex_dtypes = pd . Series ( odict ( [ ( '<STR_LIT:a>' , np . int64 ) , <EOL> ( '<STR_LIT:b>' , np . bool ) , <EOL> ( '<STR_LIT:c>' , np . float64 ) ] ) ) <EOL> ex_ftypes = pd . Series ( odict ( [ ( '<STR_LIT:a>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:b>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:c>' , '<STR_LIT>' ) ] ) ) <EOL> assert_series_equal ( df . dtypes , ex_dtypes ) <EOL> assert_series_equal ( df . ftypes , ex_ftypes ) <EOL> assert_series_equal ( df [ : <NUM_LIT:0> ] . dtypes , ex_dtypes ) <EOL> assert_series_equal ( df [ : <NUM_LIT:0> ] . ftypes , ex_ftypes ) <EOL> def test_dtypes_are_correct_after_column_slice ( self ) : <EOL> df = pd . DataFrame ( index = range ( <NUM_LIT:5> ) , columns = list ( "<STR_LIT:abc>" ) , dtype = np . float_ ) <EOL> odict = compat . OrderedDict <EOL> assert_series_equal ( df . dtypes , <EOL> pd . Series ( odict ( [ ( '<STR_LIT:a>' , np . float_ ) , <EOL> ( '<STR_LIT:b>' , np . float_ ) , <EOL> ( '<STR_LIT:c>' , np . float_ ) ] ) ) ) <EOL> assert_series_equal ( df . iloc [ : , <NUM_LIT:2> : ] . dtypes , <EOL> pd . Series ( odict ( [ ( '<STR_LIT:c>' , np . float_ ) ] ) ) ) <EOL> assert_series_equal ( df . dtypes , <EOL> pd . Series ( odict ( [ ( '<STR_LIT:a>' , np . float_ ) , <EOL> ( '<STR_LIT:b>' , np . float_ ) , <EOL> ( '<STR_LIT:c>' , np . float_ ) ] ) ) ) <EOL> def test_select_dtypes_include ( self ) : <EOL> df = DataFrame ( { '<STR_LIT:a>' : list ( '<STR_LIT:abc>' ) , <EOL> '<STR_LIT:b>' : list ( range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) , <EOL> '<STR_LIT:c>' : np . arange ( <NUM_LIT:3> , <NUM_LIT:6> ) . astype ( '<STR_LIT>' ) , <EOL> '<STR_LIT:d>' : np . arange ( <NUM_LIT> , <NUM_LIT> , dtype = '<STR_LIT>' ) , <EOL> '<STR_LIT:e>' : [ True , False , True ] , <EOL> '<STR_LIT:f>' : pd . Categorical ( list ( '<STR_LIT:abc>' ) ) } ) <EOL> ri = df . select_dtypes ( include = [ np . number ] ) <EOL> ei = df [ [ '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] ] <EOL> assert_frame_equal ( ri , ei ) <EOL> ri = df . select_dtypes ( include = [ np . number , '<STR_LIT>' ] ) <EOL> ei = df [ [ '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:f>' ] ] <EOL> assert_frame_equal ( ri , ei ) <EOL> def test_select_dtypes_exclude ( self ) : <EOL> df = DataFrame ( { '<STR_LIT:a>' : list ( '<STR_LIT:abc>' ) , <EOL> '<STR_LIT:b>' : list ( range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) , <EOL> '<STR_LIT:c>' : np . arange ( <NUM_LIT:3> , <NUM_LIT:6> ) . astype ( '<STR_LIT>' ) , <EOL> '<STR_LIT:d>' : np . arange ( <NUM_LIT> , <NUM_LIT> , dtype = '<STR_LIT>' ) , <EOL> '<STR_LIT:e>' : [ True , False , True ] } ) <EOL> re = df . select_dtypes ( exclude = [ np . number ] ) <EOL> ee = df [ [ '<STR_LIT:a>' , '<STR_LIT:e>' ] ] <EOL> assert_frame_equal ( re , ee ) <EOL> def test_select_dtypes_exclude_include ( self ) : <EOL> df = DataFrame ( { '<STR_LIT:a>' : list ( '<STR_LIT:abc>' ) , <EOL> '<STR_LIT:b>' : list ( range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) , <EOL> '<STR_LIT:c>' : np . arange ( <NUM_LIT:3> , <NUM_LIT:6> ) . astype ( '<STR_LIT>' ) , <EOL> '<STR_LIT:d>' : np . arange ( <NUM_LIT> , <NUM_LIT> , dtype = '<STR_LIT>' ) , <EOL> '<STR_LIT:e>' : [ True , False , True ] , <EOL> '<STR_LIT:f>' : pd . date_range ( '<STR_LIT>' , periods = <NUM_LIT:3> ) . values } ) <EOL> exclude = np . datetime64 , <EOL> include = np . bool_ , '<STR_LIT>' <EOL> r = df . select_dtypes ( include = include , exclude = exclude ) <EOL> e = df [ [ '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:e>' ] ] <EOL> assert_frame_equal ( r , e ) <EOL> exclude = '<STR_LIT>' , <EOL> include = '<STR_LIT:bool>' , '<STR_LIT>' , '<STR_LIT>' <EOL> r = df . select_dtypes ( include = include , exclude = exclude ) <EOL> e = df [ [ '<STR_LIT:b>' , '<STR_LIT:e>' ] ] <EOL> assert_frame_equal ( r , e ) <EOL> def test_select_dtypes_not_an_attr_but_still_valid_dtype ( self ) : <EOL> df = DataFrame ( { '<STR_LIT:a>' : list ( '<STR_LIT:abc>' ) , <EOL> '<STR_LIT:b>' : list ( range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) , <EOL> '<STR_LIT:c>' : np . arange ( <NUM_LIT:3> , <NUM_LIT:6> ) . astype ( '<STR_LIT>' ) , <EOL> '<STR_LIT:d>' : np . arange ( <NUM_LIT> , <NUM_LIT> , dtype = '<STR_LIT>' ) , <EOL> '<STR_LIT:e>' : [ True , False , True ] , <EOL> '<STR_LIT:f>' : pd . date_range ( '<STR_LIT>' , periods = <NUM_LIT:3> ) . values } ) <EOL> df [ '<STR_LIT:g>' ] = df . f . diff ( ) <EOL> assert not hasattr ( np , '<STR_LIT>' ) <EOL> r = df . select_dtypes ( include = [ '<STR_LIT>' , '<STR_LIT:O>' ] , exclude = [ '<STR_LIT>' ] ) <EOL> e = df [ [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ] <EOL> assert_frame_equal ( r , e ) <EOL> r = df . select_dtypes ( include = [ '<STR_LIT>' , '<STR_LIT:O>' , '<STR_LIT>' ] ) <EOL> e = df [ [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:g>' ] ] <EOL> assert_frame_equal ( r , e ) <EOL> def test_select_dtypes_empty ( self ) : <EOL> df = DataFrame ( { '<STR_LIT:a>' : list ( '<STR_LIT:abc>' ) , '<STR_LIT:b>' : list ( range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) } ) <EOL> with tm . assertRaisesRegexp ( ValueError , '<STR_LIT>' <EOL> '<STR_LIT>' ) : <EOL> df . select_dtypes ( ) <EOL> def test_select_dtypes_raises_on_string ( self ) : <EOL> df = DataFrame ( { '<STR_LIT:a>' : list ( '<STR_LIT:abc>' ) , '<STR_LIT:b>' : list ( range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) } ) <EOL> with tm . assertRaisesRegexp ( TypeError , '<STR_LIT>' ) : <EOL> df . select_dtypes ( include = '<STR_LIT:object>' ) <EOL> with tm . assertRaisesRegexp ( TypeError , '<STR_LIT>' ) : <EOL> df . select_dtypes ( exclude = '<STR_LIT:object>' ) <EOL> with tm . assertRaisesRegexp ( TypeError , '<STR_LIT>' ) : <EOL> df . select_dtypes ( include = int , exclude = '<STR_LIT:object>' ) <EOL> def test_select_dtypes_bad_datetime64 ( self ) : <EOL> df = DataFrame ( { '<STR_LIT:a>' : list ( '<STR_LIT:abc>' ) , <EOL> '<STR_LIT:b>' : list ( range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) , <EOL> '<STR_LIT:c>' : np . arange ( <NUM_LIT:3> , <NUM_LIT:6> ) . astype ( '<STR_LIT>' ) , <EOL> '<STR_LIT:d>' : np . arange ( <NUM_LIT> , <NUM_LIT> , dtype = '<STR_LIT>' ) , <EOL> '<STR_LIT:e>' : [ True , False , True ] , <EOL> '<STR_LIT:f>' : pd . date_range ( '<STR_LIT>' , periods = <NUM_LIT:3> ) . values } ) <EOL> with tm . assertRaisesRegexp ( ValueError , '<STR_LIT>' ) : <EOL> df . select_dtypes ( include = [ '<STR_LIT>' ] ) <EOL> with tm . assertRaisesRegexp ( ValueError , '<STR_LIT>' ) : <EOL> df . select_dtypes ( exclude = [ '<STR_LIT>' ] ) <EOL> def test_select_dtypes_str_raises ( self ) : <EOL> df = DataFrame ( { '<STR_LIT:a>' : list ( '<STR_LIT:abc>' ) , <EOL> '<STR_LIT:g>' : list ( u ( '<STR_LIT:abc>' ) ) , <EOL> '<STR_LIT:b>' : list ( range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) , <EOL> '<STR_LIT:c>' : np . arange ( <NUM_LIT:3> , <NUM_LIT:6> ) . astype ( '<STR_LIT>' ) , <EOL> '<STR_LIT:d>' : np . arange ( <NUM_LIT> , <NUM_LIT> , dtype = '<STR_LIT>' ) , <EOL> '<STR_LIT:e>' : [ True , False , True ] , <EOL> '<STR_LIT:f>' : pd . date_range ( '<STR_LIT>' , periods = <NUM_LIT:3> ) . values } ) <EOL> string_dtypes = set ( ( str , '<STR_LIT:str>' , np . string_ , '<STR_LIT>' , <EOL> '<STR_LIT>' , np . unicode_ , '<STR_LIT>' ) ) <EOL> try : <EOL> string_dtypes . add ( unicode ) <EOL> except NameError : <EOL> pass <EOL> for dt in string_dtypes : <EOL> with tm . assertRaisesRegexp ( TypeError , <EOL> '<STR_LIT>' ) : <EOL> df . select_dtypes ( include = [ dt ] ) <EOL> with tm . assertRaisesRegexp ( TypeError , <EOL> '<STR_LIT>' ) : <EOL> df . select_dtypes ( exclude = [ dt ] ) <EOL> def test_select_dtypes_bad_arg_raises ( self ) : <EOL> df = DataFrame ( { '<STR_LIT:a>' : list ( '<STR_LIT:abc>' ) , <EOL> '<STR_LIT:g>' : list ( u ( '<STR_LIT:abc>' ) ) , <EOL> '<STR_LIT:b>' : list ( range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) , <EOL> '<STR_LIT:c>' : np . arange ( <NUM_LIT:3> , <NUM_LIT:6> ) . astype ( '<STR_LIT>' ) , <EOL> '<STR_LIT:d>' : np . arange ( <NUM_LIT> , <NUM_LIT> , dtype = '<STR_LIT>' ) , <EOL> '<STR_LIT:e>' : [ True , False , True ] , <EOL> '<STR_LIT:f>' : pd . date_range ( '<STR_LIT>' , periods = <NUM_LIT:3> ) . values } ) <EOL> with tm . assertRaisesRegexp ( TypeError , '<STR_LIT>' ) : <EOL> df . select_dtypes ( [ '<STR_LIT>' ] ) <EOL> def test_select_dtypes_typecodes ( self ) : <EOL> df = mkdf ( <NUM_LIT:30> , <NUM_LIT:3> , data_gen_f = lambda x , y : np . random . random ( ) ) <EOL> expected = df <EOL> FLOAT_TYPES = list ( np . typecodes [ '<STR_LIT>' ] ) <EOL> assert_frame_equal ( df . select_dtypes ( FLOAT_TYPES ) , expected ) <EOL> def test_dtypes_gh8722 ( self ) : <EOL> self . mixed_frame [ '<STR_LIT:bool>' ] = self . mixed_frame [ '<STR_LIT:A>' ] > <NUM_LIT:0> <EOL> result = self . mixed_frame . dtypes <EOL> expected = Series ( dict ( ( k , v . dtype ) <EOL> for k , v in compat . iteritems ( self . mixed_frame ) ) , <EOL> index = result . index ) <EOL> assert_series_equal ( result , expected ) <EOL> with option_context ( '<STR_LIT>' , True ) : <EOL> df = DataFrame ( [ [ <NUM_LIT:1> ] ] ) <EOL> result = df . dtypes <EOL> assert_series_equal ( result , Series ( { <NUM_LIT:0> : np . dtype ( '<STR_LIT>' ) } ) ) <EOL> def test_ftypes ( self ) : <EOL> frame = self . mixed_float <EOL> expected = Series ( dict ( A = '<STR_LIT>' , <EOL> B = '<STR_LIT>' , <EOL> C = '<STR_LIT>' , <EOL> D = '<STR_LIT>' ) ) . sort_values ( ) <EOL> result = frame . ftypes . sort_values ( ) <EOL> assert_series_equal ( result , expected ) <EOL> def test_astype ( self ) : <EOL> casted = self . frame . astype ( int ) <EOL> expected = DataFrame ( self . frame . values . astype ( int ) , <EOL> index = self . frame . index , <EOL> columns = self . frame . columns ) <EOL> assert_frame_equal ( casted , expected ) <EOL> casted = self . frame . astype ( np . int32 ) <EOL> expected = DataFrame ( self . frame . values . astype ( np . int32 ) , <EOL> index = self . frame . index , <EOL> columns = self . frame . columns ) <EOL> assert_frame_equal ( casted , expected ) <EOL> self . frame [ '<STR_LIT:foo>' ] = '<STR_LIT:5>' <EOL> casted = self . frame . astype ( int ) <EOL> expected = DataFrame ( self . frame . values . astype ( int ) , <EOL> index = self . frame . index , <EOL> columns = self . frame . columns ) <EOL> assert_frame_equal ( casted , expected ) <EOL> def _check_cast ( df , v ) : <EOL> self . assertEqual ( <EOL> list ( set ( [ s . dtype . name <EOL> for _ , s in compat . iteritems ( df ) ] ) ) [ <NUM_LIT:0> ] , v ) <EOL> mn = self . all_mixed . _get_numeric_data ( ) . copy ( ) <EOL> mn [ '<STR_LIT>' ] = np . array ( <NUM_LIT> , dtype = '<STR_LIT>' ) <EOL> mn [ '<STR_LIT>' ] = np . array ( <NUM_LIT> , dtype = '<STR_LIT>' ) <EOL> casted = mn . astype ( '<STR_LIT>' ) <EOL> _check_cast ( casted , '<STR_LIT>' ) <EOL> casted = mn . astype ( '<STR_LIT>' ) <EOL> _check_cast ( casted , '<STR_LIT>' ) <EOL> casted = self . mixed_float . reindex ( columns = [ '<STR_LIT:A>' , '<STR_LIT:B>' ] ) . astype ( '<STR_LIT>' ) <EOL> _check_cast ( casted , '<STR_LIT>' ) <EOL> casted = mn . reindex ( columns = [ '<STR_LIT>' ] ) . astype ( '<STR_LIT>' ) <EOL> _check_cast ( casted , '<STR_LIT>' ) <EOL> casted = self . mixed_float . reindex ( columns = [ '<STR_LIT:A>' , '<STR_LIT:B>' ] ) . astype ( '<STR_LIT>' ) <EOL> _check_cast ( casted , '<STR_LIT>' ) <EOL> casted = mn . astype ( '<STR_LIT>' ) <EOL> _check_cast ( casted , '<STR_LIT>' ) <EOL> casted = mn . astype ( '<STR_LIT>' ) <EOL> _check_cast ( casted , '<STR_LIT>' ) <EOL> casted = mn . astype ( '<STR_LIT:O>' ) <EOL> _check_cast ( casted , '<STR_LIT:object>' ) <EOL> def test_astype_with_exclude_string ( self ) : <EOL> df = self . frame . copy ( ) <EOL> expected = self . frame . astype ( int ) <EOL> df [ '<STR_LIT:string>' ] = '<STR_LIT:foo>' <EOL> casted = df . astype ( int , raise_on_error = False ) <EOL> expected [ '<STR_LIT:string>' ] = '<STR_LIT:foo>' <EOL> assert_frame_equal ( casted , expected ) <EOL> df = self . frame . copy ( ) <EOL> expected = self . frame . astype ( np . int32 ) <EOL> df [ '<STR_LIT:string>' ] = '<STR_LIT:foo>' <EOL> casted = df . astype ( np . int32 , raise_on_error = False ) <EOL> expected [ '<STR_LIT:string>' ] = '<STR_LIT:foo>' <EOL> assert_frame_equal ( casted , expected ) <EOL> def test_astype_with_view ( self ) : <EOL> tf = self . mixed_float . reindex ( columns = [ '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ] ) <EOL> casted = tf . astype ( np . int64 ) <EOL> casted = tf . astype ( np . float32 ) <EOL> tf = np . round ( self . frame ) . astype ( np . int32 ) <EOL> casted = tf . astype ( np . float32 , copy = False ) <EOL> tf = self . frame . astype ( np . float64 ) <EOL> casted = tf . astype ( np . int64 , copy = False ) <EOL> def test_astype_cast_nan_int ( self ) : <EOL> df = DataFrame ( data = { "<STR_LIT>" : [ <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> , np . nan ] } ) <EOL> self . assertRaises ( ValueError , df . astype , np . int64 ) <EOL> def test_astype_str ( self ) : <EOL> a = Series ( date_range ( '<STR_LIT>' , periods = <NUM_LIT:5> ) ) <EOL> b = Series ( date_range ( '<STR_LIT>' , periods = <NUM_LIT:5> , tz = '<STR_LIT>' ) ) <EOL> c = Series ( [ Timedelta ( x , unit = '<STR_LIT:d>' ) for x in range ( <NUM_LIT:5> ) ] ) <EOL> d = Series ( range ( <NUM_LIT:5> ) ) <EOL> e = Series ( [ <NUM_LIT:0.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> df = DataFrame ( { '<STR_LIT:a>' : a , '<STR_LIT:b>' : b , '<STR_LIT:c>' : c , '<STR_LIT:d>' : d , '<STR_LIT:e>' : e } ) <EOL> for tt in set ( [ str , compat . text_type ] ) : <EOL> result = df . astype ( tt ) <EOL> expected = DataFrame ( { <EOL> '<STR_LIT:a>' : list ( map ( tt , map ( lambda x : Timestamp ( x ) . _date_repr , <EOL> a . _values ) ) ) , <EOL> '<STR_LIT:b>' : list ( map ( tt , map ( Timestamp , b . _values ) ) ) , <EOL> '<STR_LIT:c>' : list ( map ( tt , map ( lambda x : Timedelta ( x ) <EOL> . _repr_base ( format = '<STR_LIT:all>' ) , c . _values ) ) ) , <EOL> '<STR_LIT:d>' : list ( map ( tt , d . _values ) ) , <EOL> '<STR_LIT:e>' : list ( map ( tt , e . _values ) ) , <EOL> } ) <EOL> assert_frame_equal ( result , expected ) <EOL> for tt in set ( [ str , compat . text_type ] ) : <EOL> result = DataFrame ( [ np . NaN ] ) . astype ( tt ) <EOL> expected = DataFrame ( [ '<STR_LIT>' ] ) <EOL> assert_frame_equal ( result , expected ) <EOL> result = DataFrame ( [ <NUM_LIT> ] ) . astype ( tt ) <EOL> expected = DataFrame ( [ '<STR_LIT>' ] ) <EOL> assert_frame_equal ( result , expected ) <EOL> def test_timedeltas ( self ) : <EOL> df = DataFrame ( dict ( A = Series ( date_range ( '<STR_LIT>' , periods = <NUM_LIT:3> , <EOL> freq = '<STR_LIT:D>' ) ) , <EOL> B = Series ( [ timedelta ( days = i ) for i in range ( <NUM_LIT:3> ) ] ) ) ) <EOL> result = df . get_dtype_counts ( ) . sort_values ( ) <EOL> expected = Series ( <EOL> { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> } ) . sort_values ( ) <EOL> assert_series_equal ( result , expected ) <EOL> df [ '<STR_LIT:C>' ] = df [ '<STR_LIT:A>' ] + df [ '<STR_LIT:B>' ] <EOL> expected = Series ( <EOL> { '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:1> } ) . sort_values ( ) <EOL> result = df . get_dtype_counts ( ) . sort_values ( ) <EOL> assert_series_equal ( result , expected ) <EOL> df [ '<STR_LIT:D>' ] = <NUM_LIT:1> <EOL> expected = Series ( { '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> } ) . sort_values ( ) <EOL> result = df . get_dtype_counts ( ) . sort_values ( ) <EOL> assert_series_equal ( result , expected ) </s>
