<s> from datetime import datetime , timedelta , date , time <EOL> import numpy as np <EOL> import pandas as pd <EOL> import pandas . lib as lib <EOL> import pandas . util . testing as tm <EOL> from pandas . compat import u , PY2 <EOL> class TestMisc ( tm . TestCase ) : <EOL> def test_max_len_string_array ( self ) : <EOL> arr = a = np . array ( [ '<STR_LIT:foo>' , '<STR_LIT:b>' , np . nan ] , dtype = '<STR_LIT:object>' ) <EOL> self . assertTrue ( lib . max_len_string_array ( arr ) , <NUM_LIT:3> ) <EOL> arr = a . astype ( '<STR_LIT>' ) . astype ( object ) <EOL> self . assertTrue ( lib . max_len_string_array ( arr ) , <NUM_LIT:3> ) <EOL> arr = a . astype ( '<STR_LIT:S>' ) . astype ( object ) <EOL> self . assertTrue ( lib . max_len_string_array ( arr ) , <NUM_LIT:3> ) <EOL> tm . assertRaises ( TypeError , <EOL> lambda : lib . max_len_string_array ( arr . astype ( '<STR_LIT>' ) ) ) <EOL> def test_infer_dtype_bytes ( self ) : <EOL> compare = '<STR_LIT:string>' if PY2 else '<STR_LIT>' <EOL> arr = np . array ( list ( '<STR_LIT:abc>' ) , dtype = '<STR_LIT>' ) <EOL> self . assertEqual ( pd . lib . infer_dtype ( arr ) , compare ) <EOL> arr = arr . astype ( object ) <EOL> self . assertEqual ( pd . lib . infer_dtype ( arr ) , compare ) <EOL> def test_maybe_indices_to_slice_left_edge ( self ) : <EOL> target = np . arange ( <NUM_LIT:100> ) <EOL> indices = np . array ( [ ] , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertTrue ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , target [ maybe_slice ] ) <EOL> for end in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:20> , <NUM_LIT> ] : <EOL> for step in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> ] : <EOL> indices = np . arange ( <NUM_LIT:0> , end , step , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertTrue ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , <EOL> target [ maybe_slice ] ) <EOL> indices = indices [ : : - <NUM_LIT:1> ] <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertTrue ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , <EOL> target [ maybe_slice ] ) <EOL> for case in [ [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> ] , [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> ] , [ - <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:0> , - <NUM_LIT:2> ] ] : <EOL> indices = np . array ( case , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertFalse ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( maybe_slice , indices ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , target [ maybe_slice ] ) <EOL> def test_maybe_indices_to_slice_right_edge ( self ) : <EOL> target = np . arange ( <NUM_LIT:100> ) <EOL> for start in [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> ] : <EOL> for step in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> ] : <EOL> indices = np . arange ( start , <NUM_LIT> , step , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertTrue ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , <EOL> target [ maybe_slice ] ) <EOL> indices = indices [ : : - <NUM_LIT:1> ] <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertTrue ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , <EOL> target [ maybe_slice ] ) <EOL> indices = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:100> ] , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertFalse ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( maybe_slice , indices ) <EOL> with self . assertRaises ( IndexError ) : <EOL> target [ indices ] <EOL> with self . assertRaises ( IndexError ) : <EOL> target [ maybe_slice ] <EOL> indices = np . array ( [ <NUM_LIT:100> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertFalse ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( maybe_slice , indices ) <EOL> with self . assertRaises ( IndexError ) : <EOL> target [ indices ] <EOL> with self . assertRaises ( IndexError ) : <EOL> target [ maybe_slice ] <EOL> for case in [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] : <EOL> indices = np . array ( case , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertFalse ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( maybe_slice , indices ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , target [ maybe_slice ] ) <EOL> def test_maybe_indices_to_slice_both_edges ( self ) : <EOL> target = np . arange ( <NUM_LIT:10> ) <EOL> for step in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:8> , <NUM_LIT:9> ] : <EOL> indices = np . arange ( <NUM_LIT:0> , <NUM_LIT:9> , step , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertTrue ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , target [ maybe_slice ] ) <EOL> indices = indices [ : : - <NUM_LIT:1> ] <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertTrue ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , target [ maybe_slice ] ) <EOL> for case in [ [ <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:0> , - <NUM_LIT:2> ] , [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> ] ] : <EOL> indices = np . array ( case , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertFalse ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( maybe_slice , indices ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , target [ maybe_slice ] ) <EOL> def test_maybe_indices_to_slice_middle ( self ) : <EOL> target = np . arange ( <NUM_LIT:100> ) <EOL> for start , end in [ ( <NUM_LIT:2> , <NUM_LIT:10> ) , ( <NUM_LIT:5> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ] : <EOL> for step in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:20> ] : <EOL> indices = np . arange ( start , end , step , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertTrue ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , <EOL> target [ maybe_slice ] ) <EOL> indices = indices [ : : - <NUM_LIT:1> ] <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertTrue ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , <EOL> target [ maybe_slice ] ) <EOL> for case in [ [ <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:10> , <NUM_LIT:12> ] , [ <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:11> , <NUM_LIT:10> ] , [ <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT:11> ] ] : <EOL> indices = np . array ( case , dtype = np . int64 ) <EOL> maybe_slice = lib . maybe_indices_to_slice ( indices , len ( target ) ) <EOL> self . assertFalse ( isinstance ( maybe_slice , slice ) ) <EOL> self . assert_numpy_array_equal ( maybe_slice , indices ) <EOL> self . assert_numpy_array_equal ( target [ indices ] , target [ maybe_slice ] ) <EOL> def test_isinf_scalar ( self ) : <EOL> self . assertTrue ( lib . isposinf_scalar ( float ( '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( lib . isposinf_scalar ( np . inf ) ) <EOL> self . assertFalse ( lib . isposinf_scalar ( - np . inf ) ) <EOL> self . assertFalse ( lib . isposinf_scalar ( <NUM_LIT:1> ) ) <EOL> self . assertFalse ( lib . isposinf_scalar ( '<STR_LIT:a>' ) ) <EOL> self . assertTrue ( lib . isneginf_scalar ( float ( '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( lib . isneginf_scalar ( - np . inf ) ) <EOL> self . assertFalse ( lib . isneginf_scalar ( np . inf ) ) <EOL> self . assertFalse ( lib . isneginf_scalar ( <NUM_LIT:1> ) ) <EOL> self . assertFalse ( lib . isneginf_scalar ( '<STR_LIT:a>' ) ) <EOL> class Testisscalar ( tm . TestCase ) : <EOL> def test_isscalar_builtin_scalars ( self ) : <EOL> self . assertTrue ( lib . isscalar ( None ) ) <EOL> self . assertTrue ( lib . isscalar ( True ) ) <EOL> self . assertTrue ( lib . isscalar ( False ) ) <EOL> self . assertTrue ( lib . isscalar ( <NUM_LIT:0.> ) ) <EOL> self . assertTrue ( lib . isscalar ( np . nan ) ) <EOL> self . assertTrue ( lib . isscalar ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( lib . isscalar ( b'<STR_LIT>' ) ) <EOL> self . assertTrue ( lib . isscalar ( u ( '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( lib . isscalar ( datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) ) <EOL> self . assertTrue ( lib . isscalar ( date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) ) <EOL> self . assertTrue ( lib . isscalar ( time ( <NUM_LIT:12> , <NUM_LIT:0> ) ) ) <EOL> self . assertTrue ( lib . isscalar ( timedelta ( hours = <NUM_LIT:1> ) ) ) <EOL> self . assertTrue ( lib . isscalar ( pd . NaT ) ) <EOL> def test_isscalar_builtin_nonscalars ( self ) : <EOL> self . assertFalse ( lib . isscalar ( { } ) ) <EOL> self . assertFalse ( lib . isscalar ( [ ] ) ) <EOL> self . assertFalse ( lib . isscalar ( [ <NUM_LIT:1> ] ) ) <EOL> self . assertFalse ( lib . isscalar ( ( ) ) ) <EOL> self . assertFalse ( lib . isscalar ( ( <NUM_LIT:1> , ) ) ) <EOL> self . assertFalse ( lib . isscalar ( slice ( None ) ) ) <EOL> self . assertFalse ( lib . isscalar ( Ellipsis ) ) <EOL> def test_isscalar_numpy_array_scalars ( self ) : <EOL> self . assertTrue ( lib . isscalar ( np . int64 ( <NUM_LIT:1> ) ) ) <EOL> self . assertTrue ( lib . isscalar ( np . float64 ( <NUM_LIT:1.> ) ) ) <EOL> self . assertTrue ( lib . isscalar ( np . int32 ( <NUM_LIT:1> ) ) ) <EOL> self . assertTrue ( lib . isscalar ( np . object_ ( '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( lib . isscalar ( np . str_ ( '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( lib . isscalar ( np . unicode_ ( u ( '<STR_LIT>' ) ) ) ) <EOL> self . assertTrue ( lib . isscalar ( np . bytes_ ( b'<STR_LIT>' ) ) ) <EOL> self . assertTrue ( lib . isscalar ( np . datetime64 ( '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( lib . isscalar ( np . timedelta64 ( <NUM_LIT:1> , '<STR_LIT:h>' ) ) ) <EOL> def test_isscalar_numpy_zerodim_arrays ( self ) : <EOL> for zerodim in [ np . array ( <NUM_LIT:1> ) , np . array ( '<STR_LIT>' ) , <EOL> np . array ( np . datetime64 ( '<STR_LIT>' ) ) , <EOL> np . array ( np . timedelta64 ( <NUM_LIT:1> , '<STR_LIT:h>' ) ) , <EOL> np . array ( np . datetime64 ( '<STR_LIT>' ) ) ] : <EOL> self . assertFalse ( lib . isscalar ( zerodim ) ) <EOL> self . assertTrue ( lib . isscalar ( lib . item_from_zerodim ( zerodim ) ) ) <EOL> def test_isscalar_numpy_arrays ( self ) : <EOL> self . assertFalse ( lib . isscalar ( np . array ( [ ] ) ) ) <EOL> self . assertFalse ( lib . isscalar ( np . array ( [ [ ] ] ) ) ) <EOL> self . assertFalse ( lib . isscalar ( np . matrix ( '<STR_LIT>' ) ) ) <EOL> def test_isscalar_pandas_scalars ( self ) : <EOL> self . assertTrue ( lib . isscalar ( pd . Timestamp ( '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( lib . isscalar ( pd . Timedelta ( hours = <NUM_LIT:1> ) ) ) <EOL> self . assertTrue ( lib . isscalar ( pd . Period ( '<STR_LIT>' ) ) ) <EOL> def test_lisscalar_pandas_containers ( self ) : <EOL> self . assertFalse ( lib . isscalar ( pd . Series ( ) ) ) <EOL> self . assertFalse ( lib . isscalar ( pd . Series ( [ <NUM_LIT:1> ] ) ) ) <EOL> self . assertFalse ( lib . isscalar ( pd . DataFrame ( ) ) ) <EOL> self . assertFalse ( lib . isscalar ( pd . DataFrame ( [ [ <NUM_LIT:1> ] ] ) ) ) <EOL> self . assertFalse ( lib . isscalar ( pd . Panel ( ) ) ) <EOL> self . assertFalse ( lib . isscalar ( pd . Panel ( [ [ [ <NUM_LIT:1> ] ] ] ) ) ) <EOL> self . assertFalse ( lib . isscalar ( pd . Index ( [ ] ) ) ) <EOL> self . assertFalse ( lib . isscalar ( pd . Index ( [ <NUM_LIT:1> ] ) ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import nose <EOL> nose . runmodule ( argv = [ __file__ , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> exit = False ) </s>
