|
25 | 25 | compat) |
26 | 26 |
|
27 | 27 |
|
28 | | -class TimeConversionFormats(object): |
| 28 | +class TestTimeConversionFormats(object): |
29 | 29 |
|
30 | 30 | def test_to_datetime_format(self): |
31 | 31 | values = ['1/1/2000', '1/2/2000', '1/3/2000'] |
@@ -372,7 +372,7 @@ def test_datetime_invalid_datatype(self): |
372 | 372 | pd.to_datetime(pd.to_datetime) |
373 | 373 |
|
374 | 374 |
|
375 | | -class ToDatetimeUnit(object): |
| 375 | +class TestToDatetimeUnit(object): |
376 | 376 |
|
377 | 377 | def test_unit(self): |
378 | 378 | # GH 11758 |
@@ -566,42 +566,50 @@ def test_dataframe(self): |
566 | 566 | df2 = DataFrame({'year': [2015, 2016], |
567 | 567 | 'month': [2, 20], |
568 | 568 | 'day': [4, 5]}) |
569 | | - with pytest.raises(ValueError): |
| 569 | + |
| 570 | + msg = ("cannot assemble the datetimes: time data .+ does not " |
| 571 | + "match format '%Y%m%d' \(match\)") |
| 572 | + with tm.assert_raises_regex(ValueError, msg): |
570 | 573 | to_datetime(df2) |
571 | 574 | result = to_datetime(df2, errors='coerce') |
572 | 575 | expected = Series([Timestamp('20150204 00:00:00'), |
573 | 576 | NaT]) |
574 | 577 | assert_series_equal(result, expected) |
575 | 578 |
|
576 | 579 | # extra columns |
577 | | - with pytest.raises(ValueError): |
| 580 | + msg = ("extra keys have been passed to the datetime assemblage: " |
| 581 | + "\[foo\]") |
| 582 | + with tm.assert_raises_regex(ValueError, msg): |
578 | 583 | df2 = df.copy() |
579 | 584 | df2['foo'] = 1 |
580 | 585 | to_datetime(df2) |
581 | 586 |
|
582 | 587 | # not enough |
| 588 | + msg = ('to assemble mappings requires at least that \[year, month, ' |
| 589 | + 'day\] be specified: \[.+\] is missing') |
583 | 590 | for c in [['year'], |
584 | 591 | ['year', 'month'], |
585 | 592 | ['year', 'month', 'second'], |
586 | 593 | ['month', 'day'], |
587 | 594 | ['year', 'day', 'second']]: |
588 | | - with pytest.raises(ValueError): |
| 595 | + with tm.assert_raises_regex(ValueError, msg): |
589 | 596 | to_datetime(df[c]) |
590 | 597 |
|
591 | 598 | # duplicates |
| 599 | + msg = 'cannot assemble with duplicate keys' |
592 | 600 | df2 = DataFrame({'year': [2015, 2016], |
593 | 601 | 'month': [2, 20], |
594 | 602 | 'day': [4, 5]}) |
595 | 603 | df2.columns = ['year', 'year', 'day'] |
596 | | - with pytest.raises(ValueError): |
| 604 | + with tm.assert_raises_regex(ValueError, msg): |
597 | 605 | to_datetime(df2) |
598 | 606 |
|
599 | 607 | df2 = DataFrame({'year': [2015, 2016], |
600 | 608 | 'month': [2, 20], |
601 | 609 | 'day': [4, 5], |
602 | 610 | 'hour': [4, 5]}) |
603 | 611 | df2.columns = ['year', 'month', 'day', 'day'] |
604 | | - with pytest.raises(ValueError): |
| 612 | + with tm.assert_raises_regex(ValueError, msg): |
605 | 613 | to_datetime(df2) |
606 | 614 |
|
607 | 615 | def test_dataframe_dtypes(self): |
@@ -632,7 +640,7 @@ def test_dataframe_dtypes(self): |
632 | 640 | to_datetime(df) |
633 | 641 |
|
634 | 642 |
|
635 | | -class ToDatetimeMisc(object): |
| 643 | +class TestToDatetimeMisc(object): |
636 | 644 |
|
637 | 645 | def test_index_to_datetime(self): |
638 | 646 | idx = Index(['1/1/2000', '1/2/2000', '1/3/2000']) |
|
0 commit comments