Skip to content

TST: Enable tests that aren't currently running in indexes/datetimes/test_tools.py #17405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def f(value):
if len(excess):
raise ValueError("extra keys have been passed "
"to the datetime assemblage: "
"[{excess}]".format(','.join(excess=excess)))
"[{excess}]".format(excess=','.join(excess)))

def coerce(values):
# we allow coercion to if errors allows
Expand Down
24 changes: 16 additions & 8 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
compat)


class TimeConversionFormats(object):
class TestTimeConversionFormats(object):

def test_to_datetime_format(self):
values = ['1/1/2000', '1/2/2000', '1/3/2000']
Expand Down Expand Up @@ -334,7 +334,7 @@ def test_datetime_invalid_datatype(self):
pd.to_datetime(pd.to_datetime)


class ToDatetimeUnit(object):
class TestToDatetimeUnit(object):

def test_unit(self):
# GH 11758
Expand Down Expand Up @@ -528,42 +528,50 @@ def test_dataframe(self):
df2 = DataFrame({'year': [2015, 2016],
'month': [2, 20],
'day': [4, 5]})
with pytest.raises(ValueError):

msg = ("cannot assemble the datetimes: time data .+ does not "
"match format '%Y%m%d' \(match\)")
with tm.assert_raises_regex(ValueError, msg):
to_datetime(df2)
result = to_datetime(df2, errors='coerce')
expected = Series([Timestamp('20150204 00:00:00'),
NaT])
assert_series_equal(result, expected)

# extra columns
with pytest.raises(ValueError):
msg = ("extra keys have been passed to the datetime assemblage: "
"\[foo\]")
with tm.assert_raises_regex(ValueError, msg):
df2 = df.copy()
df2['foo'] = 1
to_datetime(df2)

# not enough
msg = ('to assemble mappings requires at least that \[year, month, '
'day\] be specified: \[.+\] is missing')
for c in [['year'],
['year', 'month'],
['year', 'month', 'second'],
['month', 'day'],
['year', 'day', 'second']]:
with pytest.raises(ValueError):
with tm.assert_raises_regex(ValueError, msg):
to_datetime(df[c])

# duplicates
msg = 'cannot assemble with duplicate keys'
df2 = DataFrame({'year': [2015, 2016],
'month': [2, 20],
'day': [4, 5]})
df2.columns = ['year', 'year', 'day']
with pytest.raises(ValueError):
with tm.assert_raises_regex(ValueError, msg):
to_datetime(df2)

df2 = DataFrame({'year': [2015, 2016],
'month': [2, 20],
'day': [4, 5],
'hour': [4, 5]})
df2.columns = ['year', 'month', 'day', 'day']
with pytest.raises(ValueError):
with tm.assert_raises_regex(ValueError, msg):
to_datetime(df2)

def test_dataframe_dtypes(self):
Expand Down Expand Up @@ -594,7 +602,7 @@ def test_dataframe_dtypes(self):
to_datetime(df)


class ToDatetimeMisc(object):
class TestToDatetimeMisc(object):

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