2323from pandas import compat
2424from pandas .compat import parse_date , StringIO , lrange
2525from pandas .compat .numpy import np_array_datetime64_compat
26- from pandas .io .parsers import read_table
2726from pandas .tseries .index import date_range
2827
2928
30-
3129class ParseDatesTests (object ):
3230
3331 def test_separator_date_conflict (self ):
@@ -515,11 +513,10 @@ def test_parse_date_time_multi_level_column_name(self):
515513 tm .assert_frame_equal (result , expected )
516514
517515 def test_parse_date_time (self ):
518- # From test_date_coverter
519516 dates = np .array (['2007/1/3' , '2008/2/4' ], dtype = object )
520517 times = np .array (['05:07:09' , '06:08:00' ], dtype = object )
521518 expected = np .array ([datetime (2007 , 1 , 3 , 5 , 7 , 9 ),
522- datetime (2008 , 2 , 4 , 6 , 8 , 0 )])
519+ datetime (2008 , 2 , 4 , 6 , 8 , 0 )])
523520
524521 result = conv .parse_date_time (dates , times )
525522 self .assertTrue ((result == expected ).all ())
@@ -530,8 +527,9 @@ def test_parse_date_time(self):
5305272001-01-05, 00:00:00, 1., 11.
531528"""
532529 datecols = {'date_time' : [0 , 1 ]}
533- df = read_table (StringIO (data ), sep = ',' , header = 0 ,
534- parse_dates = datecols , date_parser = conv .parse_date_time )
530+ df = self .read_csv (StringIO (data ), sep = ',' , header = 0 ,
531+ parse_dates = datecols ,
532+ date_parser = conv .parse_date_time )
535533 self .assertIn ('date_time' , df )
536534 self .assertEqual (df .date_time .loc [0 ], datetime (2001 , 1 , 5 , 10 , 0 , 0 ))
537535
@@ -544,7 +542,7 @@ def test_parse_date_time(self):
544542
545543 date_spec = {'nominal' : [1 , 2 ], 'actual' : [1 , 3 ]}
546544 df = self .read_csv (StringIO (data ), header = None , parse_dates = date_spec ,
547- date_parser = conv .parse_date_time )
545+ date_parser = conv .parse_date_time )
548546
549547 def test_parse_date_fields (self ):
550548 years = np .array ([2007 , 2008 ])
@@ -557,9 +555,9 @@ def test_parse_date_fields(self):
557555 data = ("year, month, day, a\n 2001 , 01 , 10 , 10.\n "
558556 "2001 , 02 , 1 , 11." )
559557 datecols = {'ymd' : [0 , 1 , 2 ]}
560- df = read_table (StringIO (data ), sep = ',' , header = 0 ,
561- parse_dates = datecols ,
562- date_parser = conv .parse_date_fields )
558+ df = self . read_csv (StringIO (data ), sep = ',' , header = 0 ,
559+ parse_dates = datecols ,
560+ date_parser = conv .parse_date_fields )
563561 self .assertIn ('ymd' , df )
564562 self .assertEqual (df .ymd .loc [0 ], datetime (2001 , 1 , 10 ))
565563
@@ -571,12 +569,11 @@ def test_datetime_six_col(self):
571569 minutes = np .array ([7 , 8 ])
572570 seconds = np .array ([9 , 0 ])
573571 expected = np .array ([datetime (2007 , 1 , 3 , 5 , 7 , 9 ),
574- datetime (2008 , 2 , 4 , 6 , 8 , 0 )])
572+ datetime (2008 , 2 , 4 , 6 , 8 , 0 )])
575573
576574 result = conv .parse_all_fields (years , months , days ,
577575 hours , minutes , seconds )
578576
579-
580577 self .assertTrue ((result == expected ).all ())
581578
582579 data = """\
@@ -585,9 +582,9 @@ def test_datetime_six_col(self):
5855822001, 01, 5, 10, 0, 00, 1., 11.
586583"""
587584 datecols = {'ymdHMS' : [0 , 1 , 2 , 3 , 4 , 5 ]}
588- df = read_table (StringIO (data ), sep = ',' , header = 0 ,
589- parse_dates = datecols ,
590- date_parser = conv .parse_all_fields )
585+ df = self . read_csv (StringIO (data ), sep = ',' , header = 0 ,
586+ parse_dates = datecols ,
587+ date_parser = conv .parse_all_fields )
591588 self .assertIn ('ymdHMS' , df )
592589 self .assertEqual (df .ymdHMS .loc [0 ], datetime (2001 , 1 , 5 , 10 , 0 , 0 ))
593590
@@ -598,9 +595,9 @@ def test_datetime_fractional_seconds(self):
5985952001, 01, 5, 10, 0, 0.500000, 1., 11.
599596"""
600597 datecols = {'ymdHMS' : [0 , 1 , 2 , 3 , 4 , 5 ]}
601- df = read_table (StringIO (data ), sep = ',' , header = 0 ,
602- parse_dates = datecols ,
603- date_parser = conv .parse_all_fields )
598+ df = self . read_csv (StringIO (data ), sep = ',' , header = 0 ,
599+ parse_dates = datecols ,
600+ date_parser = conv .parse_all_fields )
604601 self .assertIn ('ymdHMS' , df )
605602 self .assertEqual (df .ymdHMS .loc [0 ], datetime (2001 , 1 , 5 , 10 , 0 , 0 ,
606603 microsecond = 123456 ))
@@ -611,9 +608,9 @@ def test_generic(self):
611608 data = "year, month, day, a\n 2001, 01, 10, 10.\n 2001, 02, 1, 11."
612609 datecols = {'ym' : [0 , 1 ]}
613610 dateconverter = lambda y , m : date (year = int (y ), month = int (m ), day = 1 )
614- df = read_table (StringIO (data ), sep = ',' , header = 0 ,
615- parse_dates = datecols ,
616- date_parser = dateconverter )
611+ df = self . read_csv (StringIO (data ), sep = ',' , header = 0 ,
612+ parse_dates = datecols ,
613+ date_parser = dateconverter )
617614 self .assertIn ('ym' , df )
618615 self .assertEqual (df .ym .loc [0 ], date (2001 , 1 , 1 ))
619616
@@ -631,10 +628,9 @@ def date_parser(date, time):
631628 date + 'T' + time + 'Z' , dtype = 'datetime64[s]' )
632629 return datetime
633630
634-
635631 df = self .read_csv (StringIO (data ), date_parser = date_parser ,
636- parse_dates = {'datetime' : ['date' , 'time' ]},
637- index_col = ['datetime' , 'prn' ])
632+ parse_dates = {'datetime' : ['date' , 'time' ]},
633+ index_col = ['datetime' , 'prn' ])
638634
639635 datetimes = np_array_datetime64_compat (['2013-11-03T19:00:00Z' ] * 3 ,
640636 dtype = 'datetime64[s]' )
@@ -644,7 +640,7 @@ def date_parser(date, time):
644640 (datetimes [1 ], 23 ),
645641 (datetimes [2 ], 13 )],
646642 names = ['datetime' , 'prn' ]))
647- assert_frame_equal (df , df_correct )
643+ tm . assert_frame_equal (df , df_correct )
648644
649645 def test_parse_date_column_with_empty_string (self ):
650646 # GH 6428
0 commit comments