23
23
from pandas import compat
24
24
from pandas .compat import parse_date , StringIO , lrange
25
25
from pandas .compat .numpy import np_array_datetime64_compat
26
- from pandas .io .parsers import read_table
27
26
from pandas .tseries .index import date_range
28
27
29
28
30
-
31
29
class ParseDatesTests (object ):
32
30
33
31
def test_separator_date_conflict (self ):
@@ -515,11 +513,10 @@ def test_parse_date_time_multi_level_column_name(self):
515
513
tm .assert_frame_equal (result , expected )
516
514
517
515
def test_parse_date_time (self ):
518
- # From test_date_coverter
519
516
dates = np .array (['2007/1/3' , '2008/2/4' ], dtype = object )
520
517
times = np .array (['05:07:09' , '06:08:00' ], dtype = object )
521
518
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 )])
523
520
524
521
result = conv .parse_date_time (dates , times )
525
522
self .assertTrue ((result == expected ).all ())
@@ -530,8 +527,9 @@ def test_parse_date_time(self):
530
527
2001-01-05, 00:00:00, 1., 11.
531
528
"""
532
529
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 )
535
533
self .assertIn ('date_time' , df )
536
534
self .assertEqual (df .date_time .loc [0 ], datetime (2001 , 1 , 5 , 10 , 0 , 0 ))
537
535
@@ -544,7 +542,7 @@ def test_parse_date_time(self):
544
542
545
543
date_spec = {'nominal' : [1 , 2 ], 'actual' : [1 , 3 ]}
546
544
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 )
548
546
549
547
def test_parse_date_fields (self ):
550
548
years = np .array ([2007 , 2008 ])
@@ -557,9 +555,9 @@ def test_parse_date_fields(self):
557
555
data = ("year, month, day, a\n 2001 , 01 , 10 , 10.\n "
558
556
"2001 , 02 , 1 , 11." )
559
557
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 )
563
561
self .assertIn ('ymd' , df )
564
562
self .assertEqual (df .ymd .loc [0 ], datetime (2001 , 1 , 10 ))
565
563
@@ -571,12 +569,11 @@ def test_datetime_six_col(self):
571
569
minutes = np .array ([7 , 8 ])
572
570
seconds = np .array ([9 , 0 ])
573
571
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 )])
575
573
576
574
result = conv .parse_all_fields (years , months , days ,
577
575
hours , minutes , seconds )
578
576
579
-
580
577
self .assertTrue ((result == expected ).all ())
581
578
582
579
data = """\
@@ -585,9 +582,9 @@ def test_datetime_six_col(self):
585
582
2001, 01, 5, 10, 0, 00, 1., 11.
586
583
"""
587
584
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 )
591
588
self .assertIn ('ymdHMS' , df )
592
589
self .assertEqual (df .ymdHMS .loc [0 ], datetime (2001 , 1 , 5 , 10 , 0 , 0 ))
593
590
@@ -598,9 +595,9 @@ def test_datetime_fractional_seconds(self):
598
595
2001, 01, 5, 10, 0, 0.500000, 1., 11.
599
596
"""
600
597
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 )
604
601
self .assertIn ('ymdHMS' , df )
605
602
self .assertEqual (df .ymdHMS .loc [0 ], datetime (2001 , 1 , 5 , 10 , 0 , 0 ,
606
603
microsecond = 123456 ))
@@ -611,9 +608,9 @@ def test_generic(self):
611
608
data = "year, month, day, a\n 2001, 01, 10, 10.\n 2001, 02, 1, 11."
612
609
datecols = {'ym' : [0 , 1 ]}
613
610
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 )
617
614
self .assertIn ('ym' , df )
618
615
self .assertEqual (df .ym .loc [0 ], date (2001 , 1 , 1 ))
619
616
@@ -631,10 +628,9 @@ def date_parser(date, time):
631
628
date + 'T' + time + 'Z' , dtype = 'datetime64[s]' )
632
629
return datetime
633
630
634
-
635
631
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' ])
638
634
639
635
datetimes = np_array_datetime64_compat (['2013-11-03T19:00:00Z' ] * 3 ,
640
636
dtype = 'datetime64[s]' )
@@ -644,7 +640,7 @@ def date_parser(date, time):
644
640
(datetimes [1 ], 23 ),
645
641
(datetimes [2 ], 13 )],
646
642
names = ['datetime' , 'prn' ]))
647
- assert_frame_equal (df , df_correct )
643
+ tm . assert_frame_equal (df , df_correct )
648
644
649
645
def test_parse_date_column_with_empty_string (self ):
650
646
# GH 6428
0 commit comments