Skip to content

Commit 505f0f2

Browse files
committed
Initial tests
1 parent e982ba2 commit 505f0f2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pandas/tests/tools/test_to_datetime.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,3 +3819,33 @@ def test_to_datetime_lxml_elementunicoderesult_with_format(cache):
38193819

38203820
out = to_datetime(Series([val]), format="%Y-%m-%d %H:%M:%S", cache=cache)
38213821
assert out.iloc[0] == Timestamp(s)
3822+
3823+
3824+
class TestForIncreasedRobustness:
3825+
def test_parse_with_no_malformed_components(self):
3826+
res = to_datetime(
3827+
"2018-10-01 12:00:00.0000000011", format="%Y-%m-%d %H:%M:%S.%f"
3828+
)
3829+
expected = Timestamp("2018-10-01 12:00:00.0000000011")
3830+
assert res == expected
3831+
3832+
def test_parse_with_malformed_day(self):
3833+
res = to_datetime(
3834+
"2018-10-. 12:00:00.0000000011", format="%Y-%m-%d %H:%M:%S.%f"
3835+
)
3836+
expected = NaT
3837+
assert res == expected
3838+
3839+
def test_parse_with_malformed_day_iso(self):
3840+
res = to_datetime("2018-10-.", format="ISO8601")
3841+
expected = NaT
3842+
assert res == expected
3843+
3844+
def test_parse_with_half_malformed_components(self):
3845+
res = to_datetime("2018-10-. 12:.:.", format="%Y-%m-%d %H:%M:%S")
3846+
expected = NaT
3847+
assert res == expected
3848+
3849+
def test_parse_with_too_many_malformed_components(self):
3850+
with pytest.raises(ValueError, match="^time data *"):
3851+
to_datetime("2018-.-. 12:.:.", format="%Y-%m-%d %H:%M:%S")

0 commit comments

Comments
 (0)