|
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'] |
@@ -334,7 +334,7 @@ def test_datetime_invalid_datatype(self): |
334 | 334 | pd.to_datetime(pd.to_datetime) |
335 | 335 |
|
336 | 336 |
|
337 | | -class ToDatetimeUnit(object): |
| 337 | +class TestToDatetimeUnit(object): |
338 | 338 |
|
339 | 339 | def test_unit(self): |
340 | 340 | # GH 11758 |
@@ -528,42 +528,50 @@ def test_dataframe(self): |
528 | 528 | df2 = DataFrame({'year': [2015, 2016], |
529 | 529 | 'month': [2, 20], |
530 | 530 | 'day': [4, 5]}) |
531 | | - with pytest.raises(ValueError): |
| 531 | + |
| 532 | + msg = ("cannot assemble the datetimes: time data 20162005 does not " |
| 533 | + "match format '%Y%m%d' \(match\)") |
| 534 | + with tm.assert_raises_regex(ValueError, msg): |
532 | 535 | to_datetime(df2) |
533 | 536 | result = to_datetime(df2, errors='coerce') |
534 | 537 | expected = Series([Timestamp('20150204 00:00:00'), |
535 | 538 | NaT]) |
536 | 539 | assert_series_equal(result, expected) |
537 | 540 |
|
538 | 541 | # extra columns |
539 | | - with pytest.raises(ValueError): |
| 542 | + msg = ("extra keys have been passed to the datetime assemblage: " |
| 543 | + "\[foo\]") |
| 544 | + with tm.assert_raises_regex(ValueError, msg): |
540 | 545 | df2 = df.copy() |
541 | 546 | df2['foo'] = 1 |
542 | 547 | to_datetime(df2) |
543 | 548 |
|
544 | 549 | # not enough |
| 550 | + msg = ('to assemble mappings requires at least that \[year, month, ' |
| 551 | + 'day\] be specified: \[.+\] is missing') |
545 | 552 | for c in [['year'], |
546 | 553 | ['year', 'month'], |
547 | 554 | ['year', 'month', 'second'], |
548 | 555 | ['month', 'day'], |
549 | 556 | ['year', 'day', 'second']]: |
550 | | - with pytest.raises(ValueError): |
| 557 | + with tm.assert_raises_regex(ValueError, msg): |
551 | 558 | to_datetime(df[c]) |
552 | 559 |
|
553 | 560 | # duplicates |
| 561 | + msg = 'cannot assemble with duplicate keys' |
554 | 562 | df2 = DataFrame({'year': [2015, 2016], |
555 | 563 | 'month': [2, 20], |
556 | 564 | 'day': [4, 5]}) |
557 | 565 | df2.columns = ['year', 'year', 'day'] |
558 | | - with pytest.raises(ValueError): |
| 566 | + with tm.assert_raises_regex(ValueError, msg): |
559 | 567 | to_datetime(df2) |
560 | 568 |
|
561 | 569 | df2 = DataFrame({'year': [2015, 2016], |
562 | 570 | 'month': [2, 20], |
563 | 571 | 'day': [4, 5], |
564 | 572 | 'hour': [4, 5]}) |
565 | 573 | df2.columns = ['year', 'month', 'day', 'day'] |
566 | | - with pytest.raises(ValueError): |
| 574 | + with tm.assert_raises_regex(ValueError, msg): |
567 | 575 | to_datetime(df2) |
568 | 576 |
|
569 | 577 | def test_dataframe_dtypes(self): |
@@ -594,7 +602,7 @@ def test_dataframe_dtypes(self): |
594 | 602 | to_datetime(df) |
595 | 603 |
|
596 | 604 |
|
597 | | -class ToDatetimeMisc(object): |
| 605 | +class TestToDatetimeMisc(object): |
598 | 606 |
|
599 | 607 | def test_index_to_datetime(self): |
600 | 608 | idx = Index(['1/1/2000', '1/2/2000', '1/3/2000']) |
|
0 commit comments