Skip to content

Commit a09ac59

Browse files
committed
Enable tests in test_tools.py
Enabled tests that currently aren't running. Small fix to make sure all tests pass. Verified that the raised messages match expectations for TestToDatetimeUnit::test_frame.
1 parent 062f6f1 commit a09ac59

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

pandas/core/tools/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ def f(value):
605605
if len(excess):
606606
raise ValueError("extra keys have been passed "
607607
"to the datetime assemblage: "
608-
"[{excess}]".format(','.join(excess=excess)))
608+
"[{excess}]".format(excess=','.join(excess)))
609609

610610
def coerce(values):
611611
# we allow coercion to if errors allows

pandas/tests/indexes/datetimes/test_tools.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
compat)
2626

2727

28-
class TimeConversionFormats(object):
28+
class TestTimeConversionFormats(object):
2929

3030
def test_to_datetime_format(self):
3131
values = ['1/1/2000', '1/2/2000', '1/3/2000']
@@ -334,7 +334,7 @@ def test_datetime_invalid_datatype(self):
334334
pd.to_datetime(pd.to_datetime)
335335

336336

337-
class ToDatetimeUnit(object):
337+
class TestToDatetimeUnit(object):
338338

339339
def test_unit(self):
340340
# GH 11758
@@ -528,42 +528,50 @@ def test_dataframe(self):
528528
df2 = DataFrame({'year': [2015, 2016],
529529
'month': [2, 20],
530530
'day': [4, 5]})
531-
with pytest.raises(ValueError):
531+
532+
msg = ("cannot assemble the datetimes: time data .+ does not "
533+
"match format '%Y%m%d' \(match\)")
534+
with tm.assert_raises_regex(ValueError, msg):
532535
to_datetime(df2)
533536
result = to_datetime(df2, errors='coerce')
534537
expected = Series([Timestamp('20150204 00:00:00'),
535538
NaT])
536539
assert_series_equal(result, expected)
537540

538541
# 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):
540545
df2 = df.copy()
541546
df2['foo'] = 1
542547
to_datetime(df2)
543548

544549
# not enough
550+
msg = ('to assemble mappings requires at least that \[year, month, '
551+
'day\] be specified: \[.+\] is missing')
545552
for c in [['year'],
546553
['year', 'month'],
547554
['year', 'month', 'second'],
548555
['month', 'day'],
549556
['year', 'day', 'second']]:
550-
with pytest.raises(ValueError):
557+
with tm.assert_raises_regex(ValueError, msg):
551558
to_datetime(df[c])
552559

553560
# duplicates
561+
msg = 'cannot assemble with duplicate keys'
554562
df2 = DataFrame({'year': [2015, 2016],
555563
'month': [2, 20],
556564
'day': [4, 5]})
557565
df2.columns = ['year', 'year', 'day']
558-
with pytest.raises(ValueError):
566+
with tm.assert_raises_regex(ValueError, msg):
559567
to_datetime(df2)
560568

561569
df2 = DataFrame({'year': [2015, 2016],
562570
'month': [2, 20],
563571
'day': [4, 5],
564572
'hour': [4, 5]})
565573
df2.columns = ['year', 'month', 'day', 'day']
566-
with pytest.raises(ValueError):
574+
with tm.assert_raises_regex(ValueError, msg):
567575
to_datetime(df2)
568576

569577
def test_dataframe_dtypes(self):
@@ -594,7 +602,7 @@ def test_dataframe_dtypes(self):
594602
to_datetime(df)
595603

596604

597-
class ToDatetimeMisc(object):
605+
class TestToDatetimeMisc(object):
598606

599607
def test_index_to_datetime(self):
600608
idx = Index(['1/1/2000', '1/2/2000', '1/3/2000'])

0 commit comments

Comments
 (0)