<s> """<STR_LIT>""" <EOL> from pandas . compat import range , map <EOL> import numpy as np <EOL> import pandas . lib as lib <EOL> def parse_date_time ( date_col , time_col ) : <EOL> date_col = _maybe_cast ( date_col ) <EOL> time_col = _maybe_cast ( time_col ) <EOL> return lib . try_parse_date_and_time ( date_col , time_col ) <EOL> def parse_date_fields ( year_col , month_col , day_col ) : <EOL> year_col = _maybe_cast ( year_col ) <EOL> month_col = _maybe_cast ( month_col ) <EOL> day_col = _maybe_cast ( day_col ) <EOL> return lib . try_parse_year_month_day ( year_col , month_col , day_col ) <EOL> def parse_all_fields ( year_col , month_col , day_col , hour_col , minute_col , <EOL> second_col ) : <EOL> year_col = _maybe_cast ( year_col ) <EOL> month_col = _maybe_cast ( month_col ) <EOL> day_col = _maybe_cast ( day_col ) <EOL> hour_col = _maybe_cast ( hour_col ) <EOL> minute_col = _maybe_cast ( minute_col ) <EOL> second_col = _maybe_cast ( second_col ) <EOL> return lib . try_parse_datetime_components ( year_col , month_col , day_col , <EOL> hour_col , minute_col , second_col ) <EOL> def generic_parser ( parse_func , * cols ) : <EOL> N = _check_columns ( cols ) <EOL> results = np . empty ( N , dtype = object ) <EOL> for i in range ( N ) : <EOL> args = [ c [ i ] for c in cols ] <EOL> results [ i ] = parse_func ( * args ) <EOL> return results <EOL> def _maybe_cast ( arr ) : <EOL> if not arr . dtype . type == np . object_ : <EOL> arr = np . array ( arr , dtype = object ) <EOL> return arr <EOL> def _check_columns ( cols ) : <EOL> if not len ( cols ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> head , tail = cols [ <NUM_LIT:0> ] , cols [ <NUM_LIT:1> : ] <EOL> N = len ( head ) <EOL> for i , n in enumerate ( map ( len , tail ) ) : <EOL> if n != N : <EOL> raise AssertionError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( N , i , n ) ) <EOL> return N </s>
