<s> from datetime import datetime , timedelta <EOL> import numpy as np <EOL> import pandas as pd <EOL> from pandas import ( Index , Series , DataFrame , date_range ) <EOL> from pandas . core . index import MultiIndex <EOL> from pandas . compat import StringIO , lrange , range , u <EOL> from pandas import compat <EOL> import pandas . util . testing as tm <EOL> from . common import TestData <EOL> class TestSeriesRepr ( TestData , tm . TestCase ) : <EOL> _multiprocess_can_split_ = True <EOL> def test_multilevel_name_print ( self ) : <EOL> index = MultiIndex ( levels = [ [ '<STR_LIT:foo>' , '<STR_LIT:bar>' , '<STR_LIT>' , '<STR_LIT>' ] , [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ] , <EOL> labels = [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ] , <EOL> names = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> s = Series ( lrange ( <NUM_LIT:0> , len ( index ) ) , index = index , name = '<STR_LIT>' ) <EOL> expected = [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> expected = "<STR_LIT:\n>" . join ( expected ) <EOL> self . assertEqual ( repr ( s ) , expected ) <EOL> def test_name_printing ( self ) : <EOL> s = Series ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> s . name = "<STR_LIT:test>" <EOL> self . assertIn ( "<STR_LIT>" , repr ( s ) ) <EOL> s . name = None <EOL> self . assertNotIn ( "<STR_LIT>" , repr ( s ) ) <EOL> s = Series ( lrange ( <NUM_LIT:0> , <NUM_LIT:1000> ) ) <EOL> s . name = "<STR_LIT:test>" <EOL> self . assertIn ( "<STR_LIT>" , repr ( s ) ) <EOL> s . name = None <EOL> self . assertNotIn ( "<STR_LIT>" , repr ( s ) ) <EOL> s = Series ( index = date_range ( '<STR_LIT>' , '<STR_LIT>' ) , name = '<STR_LIT:test>' ) <EOL> self . assertIn ( "<STR_LIT>" , repr ( s ) ) <EOL> def test_repr ( self ) : <EOL> str ( self . ts ) <EOL> str ( self . series ) <EOL> str ( self . series . astype ( int ) ) <EOL> str ( self . objSeries ) <EOL> str ( Series ( tm . randn ( <NUM_LIT:1000> ) , index = np . arange ( <NUM_LIT:1000> ) ) ) <EOL> str ( Series ( tm . randn ( <NUM_LIT:1000> ) , index = np . arange ( <NUM_LIT:1000> , <NUM_LIT:0> , step = - <NUM_LIT:1> ) ) ) <EOL> str ( self . empty ) <EOL> self . series [ <NUM_LIT:5> : <NUM_LIT:7> ] = np . NaN <EOL> str ( self . series ) <EOL> ots = self . ts . astype ( '<STR_LIT:O>' ) <EOL> ots [ : : <NUM_LIT:2> ] = None <EOL> repr ( ots ) <EOL> for name in [ '<STR_LIT>' , <NUM_LIT:1> , <NUM_LIT> , '<STR_LIT:foo>' , u ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT:foo>' , '<STR_LIT:bar>' , '<STR_LIT>' ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( '<STR_LIT:foo>' , <NUM_LIT:1> , <NUM_LIT> ) , <EOL> ( u ( '<STR_LIT>' ) , u ( '<STR_LIT>' ) , u ( '<STR_LIT>' ) ) , <EOL> ( u ( '<STR_LIT>' ) , '<STR_LIT:bar>' ) ] : <EOL> self . series . name = name <EOL> repr ( self . series ) <EOL> biggie = Series ( tm . randn ( <NUM_LIT:1000> ) , index = np . arange ( <NUM_LIT:1000> ) , <EOL> name = ( '<STR_LIT:foo>' , '<STR_LIT:bar>' , '<STR_LIT>' ) ) <EOL> repr ( biggie ) <EOL> ser = Series ( np . random . randn ( <NUM_LIT:100> ) , name = <NUM_LIT:0> ) <EOL> rep_str = repr ( ser ) <EOL> self . assertIn ( "<STR_LIT>" , rep_str ) <EOL> ser = Series ( np . random . randn ( <NUM_LIT> ) , name = <NUM_LIT:0> ) <EOL> rep_str = repr ( ser ) <EOL> self . assertIn ( "<STR_LIT>" , rep_str ) <EOL> ser = Series ( [ "<STR_LIT>" ] , name = "<STR_LIT>" , index = [ "<STR_LIT>" ] ) <EOL> self . assertFalse ( "<STR_LIT:\t>" in repr ( ser ) ) <EOL> self . assertFalse ( "<STR_LIT:\r>" in repr ( ser ) ) <EOL> self . assertFalse ( "<STR_LIT>" in repr ( ser ) ) <EOL> s = Series ( [ ] , dtype = np . int64 , name = '<STR_LIT:foo>' ) <EOL> self . assertEqual ( repr ( s ) , '<STR_LIT>' ) <EOL> s = Series ( [ ] , dtype = np . int64 , name = None ) <EOL> self . assertEqual ( repr ( s ) , '<STR_LIT>' ) <EOL> def test_tidy_repr ( self ) : <EOL> a = Series ( [ u ( "<STR_LIT>" ) ] * <NUM_LIT:1000> ) <EOL> a . name = '<STR_LIT>' <EOL> repr ( a ) <EOL> def test_repr_bool_fails ( self ) : <EOL> s = Series ( [ DataFrame ( np . random . randn ( <NUM_LIT:2> , <NUM_LIT:2> ) ) for i in range ( <NUM_LIT:5> ) ] ) <EOL> import sys <EOL> buf = StringIO ( ) <EOL> tmp = sys . stderr <EOL> sys . stderr = buf <EOL> try : <EOL> repr ( s ) <EOL> finally : <EOL> sys . stderr = tmp <EOL> self . assertEqual ( buf . getvalue ( ) , '<STR_LIT>' ) <EOL> def test_repr_name_iterable_indexable ( self ) : <EOL> s = Series ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , name = np . int64 ( <NUM_LIT:3> ) ) <EOL> repr ( s ) <EOL> s . name = ( u ( "<STR_LIT>" ) , ) * <NUM_LIT:2> <EOL> repr ( s ) <EOL> def test_repr_should_return_str ( self ) : <EOL> data = [ <NUM_LIT:8> , <NUM_LIT:5> , <NUM_LIT:3> , <NUM_LIT:5> ] <EOL> index1 = [ u ( "<STR_LIT>" ) , u ( "<STR_LIT>" ) , u ( "<STR_LIT>" ) , u ( "<STR_LIT>" ) ] <EOL> df = Series ( data , index = index1 ) <EOL> self . assertTrue ( type ( df . __repr__ ( ) == str ) ) <EOL> def test_repr_max_rows ( self ) : <EOL> with pd . option_context ( '<STR_LIT>' , None ) : <EOL> str ( Series ( range ( <NUM_LIT> ) ) ) <EOL> def test_unicode_string_with_unicode ( self ) : <EOL> df = Series ( [ u ( "<STR_LIT>" ) ] , name = u ( "<STR_LIT>" ) ) <EOL> if compat . PY3 : <EOL> str ( df ) <EOL> else : <EOL> compat . text_type ( df ) <EOL> def test_bytestring_with_unicode ( self ) : <EOL> df = Series ( [ u ( "<STR_LIT>" ) ] , name = u ( "<STR_LIT>" ) ) <EOL> if compat . PY3 : <EOL> bytes ( df ) <EOL> else : <EOL> str ( df ) <EOL> def test_timeseries_repr_object_dtype ( self ) : <EOL> index = Index ( [ datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) + timedelta ( i ) <EOL> for i in range ( <NUM_LIT:1000> ) ] , dtype = object ) <EOL> ts = Series ( np . random . randn ( len ( index ) ) , index ) <EOL> repr ( ts ) <EOL> ts = tm . makeTimeSeries ( <NUM_LIT:1000> ) <EOL> self . assertTrue ( repr ( ts ) . splitlines ( ) [ - <NUM_LIT:1> ] . startswith ( '<STR_LIT>' ) ) <EOL> ts2 = ts . ix [ np . random . randint ( <NUM_LIT:0> , len ( ts ) - <NUM_LIT:1> , <NUM_LIT> ) ] <EOL> repr ( ts2 ) . splitlines ( ) [ - <NUM_LIT:1> ] </s>
