Skip to content

Commit 77425c4

Browse files
jschendelalanbato
authored andcommitted
TST: Enable tests in test_tools.py (pandas-dev#17405)
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 281c067 commit 77425c4

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']
@@ -372,7 +372,7 @@ def test_datetime_invalid_datatype(self):
372372
pd.to_datetime(pd.to_datetime)
373373

374374

375-
class ToDatetimeUnit(object):
375+
class TestToDatetimeUnit(object):
376376

377377
def test_unit(self):
378378
# GH 11758
@@ -566,42 +566,50 @@ def test_dataframe(self):
566566
df2 = DataFrame({'year': [2015, 2016],
567567
'month': [2, 20],
568568
'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):
570573
to_datetime(df2)
571574
result = to_datetime(df2, errors='coerce')
572575
expected = Series([Timestamp('20150204 00:00:00'),
573576
NaT])
574577
assert_series_equal(result, expected)
575578

576579
# 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):
578583
df2 = df.copy()
579584
df2['foo'] = 1
580585
to_datetime(df2)
581586

582587
# not enough
588+
msg = ('to assemble mappings requires at least that \[year, month, '
589+
'day\] be specified: \[.+\] is missing')
583590
for c in [['year'],
584591
['year', 'month'],
585592
['year', 'month', 'second'],
586593
['month', 'day'],
587594
['year', 'day', 'second']]:
588-
with pytest.raises(ValueError):
595+
with tm.assert_raises_regex(ValueError, msg):
589596
to_datetime(df[c])
590597

591598
# duplicates
599+
msg = 'cannot assemble with duplicate keys'
592600
df2 = DataFrame({'year': [2015, 2016],
593601
'month': [2, 20],
594602
'day': [4, 5]})
595603
df2.columns = ['year', 'year', 'day']
596-
with pytest.raises(ValueError):
604+
with tm.assert_raises_regex(ValueError, msg):
597605
to_datetime(df2)
598606

599607
df2 = DataFrame({'year': [2015, 2016],
600608
'month': [2, 20],
601609
'day': [4, 5],
602610
'hour': [4, 5]})
603611
df2.columns = ['year', 'month', 'day', 'day']
604-
with pytest.raises(ValueError):
612+
with tm.assert_raises_regex(ValueError, msg):
605613
to_datetime(df2)
606614

607615
def test_dataframe_dtypes(self):
@@ -632,7 +640,7 @@ def test_dataframe_dtypes(self):
632640
to_datetime(df)
633641

634642

635-
class ToDatetimeMisc(object):
643+
class TestToDatetimeMisc(object):
636644

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

0 commit comments

Comments
 (0)