Skip to content

Commit 5351805

Browse files
This avoids failure to_datetime when value passed is None. This fix is for pandas versions > 0.24
Closes #30011
1 parent 704516f commit 5351805

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/indexes/datetimes/test_tools.py

+19
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ def test_to_datetime_format_YYYYMMDD(self, cache):
101101
expected = Series(["20121231", "20141231", "NaT"], dtype="M8[ns]")
102102
tm.assert_series_equal(result, expected)
103103

104+
@pytest.mark.parametrize(
105+
"input_s, expected",
106+
[
107+
# strings with None
108+
[
109+
Series(["19801222", None, "20010112"]),
110+
Series([Timestamp("19801222"), Timestamp(None), Timestamp("20010112")]),
111+
],
112+
# Integers with None
113+
[
114+
Series([19801222, None, 20010112]),
115+
Series([Timestamp("19801222"), Timestamp(None), Timestamp("20010112")]),
116+
],
117+
],
118+
)
119+
def test_to_datetime_format_YYYYMMDD_with_none(self, input_s, expected):
120+
result = pd.to_datetime(input_s, format="%Y%m%d")
121+
tm.assert_series_equal(result, expected)
122+
104123
@pytest.mark.parametrize(
105124
"input_s, expected",
106125
[

0 commit comments

Comments
 (0)