<s> import io <EOL> import six <EOL> @ classmethod <EOL> def from_csv ( cls , path , column_names = None , column_types = None , row_names = None , skip_lines = <NUM_LIT:0> , header = True , sniff_limit = <NUM_LIT:0> , encoding = '<STR_LIT:utf-8>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> from agate import csv <EOL> from agate . table import Table <EOL> close = False <EOL> if hasattr ( path , '<STR_LIT>' ) : <EOL> f = path <EOL> else : <EOL> f = io . open ( path , encoding = encoding ) <EOL> close = True <EOL> if isinstance ( skip_lines , int ) : <EOL> while skip_lines > <NUM_LIT:0> : <EOL> f . readline ( ) <EOL> skip_lines -= <NUM_LIT:1> <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> start = f . tell ( ) <EOL> if sniff_limit is None : <EOL> kwargs [ '<STR_LIT>' ] = csv . Sniffer ( ) . sniff ( f . read ( ) ) <EOL> elif sniff_limit > <NUM_LIT:0> : <EOL> kwargs [ '<STR_LIT>' ] = csv . Sniffer ( ) . sniff ( f . read ( sniff_limit ) ) <EOL> f . seek ( start ) <EOL> if six . PY2 : <EOL> f = six . StringIO ( f . read ( ) . encode ( '<STR_LIT:utf-8>' ) ) <EOL> reader = csv . reader ( f , header = header , ** kwargs ) <EOL> if header : <EOL> if column_names is None : <EOL> column_names = next ( reader ) <EOL> else : <EOL> next ( reader ) <EOL> rows = tuple ( reader ) <EOL> if close : <EOL> f . close ( ) <EOL> return Table ( rows , column_names , column_types , row_names = row_names ) </s>
