From df3192f897c185243244ba3bead811d8801ec27d Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Sun, 23 Feb 2020 18:14:15 -0600 Subject: [PATCH 1/6] Add to_datetime test --- pandas/tests/indexes/datetimes/test_tools.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index 13723f6455bff..292184bacee66 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -2315,3 +2315,7 @@ def test_nullable_integer_to_datetime(): tm.assert_series_equal(res, expected) # Check that ser isn't mutated tm.assert_series_equal(ser, ser_copy) + +def test_na_to_datetime(nulls_fixture): + result = pd.to_datetime([nulls_fixture]) + assert result[0] is pd.NaT \ No newline at end of file From 5e227236b1174991973223bd49a0a5a84bf9aead Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Sun, 23 Feb 2020 18:15:21 -0600 Subject: [PATCH 2/6] Check for NA --- pandas/_libs/tslibs/nattype.pyx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 9f6f401a1a5f5..68a25d0cc481a 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -22,6 +22,8 @@ from pandas._libs.tslibs.util cimport ( get_nat, is_integer_object, is_float_object, is_datetime64_object, is_timedelta64_object) +from pandas._libs.missing cimport C_NA + # ---------------------------------------------------------------------- # Constants @@ -763,7 +765,7 @@ NaT = c_NaT # Python-visible cdef inline bint checknull_with_nat(object val): """ utility to check if a value is a nat or not """ - return val is None or util.is_nan(val) or val is c_NaT + return val is None or util.is_nan(val) or val is c_NaT or val is C_NA cpdef bint is_null_datetimelike(object val, bint inat_is_null=True): From fd8e28e863d5aa2db9582c67f081865179976c5c Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Sun, 23 Feb 2020 18:17:20 -0600 Subject: [PATCH 3/6] Update whatsnew --- doc/source/whatsnew/v1.0.2.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.0.2.rst b/doc/source/whatsnew/v1.0.2.rst index f491774991090..6d381b67b2183 100644 --- a/doc/source/whatsnew/v1.0.2.rst +++ b/doc/source/whatsnew/v1.0.2.rst @@ -62,6 +62,7 @@ Bug fixes **Datetimelike** - Bug in :meth:`DataFrame.reindex` and :meth:`Series.reindex` when reindexing with a tz-aware index (:issue:`26683`) +- Bug where :func:`to_datetime` would raise when passed ``pd.NA`` (:issue:``) **Categorical** From fddbfd03d05174dc88b863a72bfc89dbddd1be7e Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Sun, 23 Feb 2020 18:18:57 -0600 Subject: [PATCH 4/6] Blacken --- pandas/tests/indexes/datetimes/test_tools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index 292184bacee66..dc6f0f1d34bc2 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -2316,6 +2316,7 @@ def test_nullable_integer_to_datetime(): # Check that ser isn't mutated tm.assert_series_equal(ser, ser_copy) + def test_na_to_datetime(nulls_fixture): result = pd.to_datetime([nulls_fixture]) - assert result[0] is pd.NaT \ No newline at end of file + assert result[0] is pd.NaT From deac9c42f2057e8fa1d612ba38b3c0df1b61b6e1 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Sun, 23 Feb 2020 18:28:45 -0600 Subject: [PATCH 5/6] Issue number --- doc/source/whatsnew/v1.0.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.2.rst b/doc/source/whatsnew/v1.0.2.rst index 6d381b67b2183..d3b1442953e41 100644 --- a/doc/source/whatsnew/v1.0.2.rst +++ b/doc/source/whatsnew/v1.0.2.rst @@ -62,7 +62,7 @@ Bug fixes **Datetimelike** - Bug in :meth:`DataFrame.reindex` and :meth:`Series.reindex` when reindexing with a tz-aware index (:issue:`26683`) -- Bug where :func:`to_datetime` would raise when passed ``pd.NA`` (:issue:``) +- Bug where :func:`to_datetime` would raise when passed ``pd.NA`` (:issue:`32213`) **Categorical** From e391db1af81fabc52f40df204079f8a51f20c7ce Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Sun, 23 Feb 2020 19:45:27 -0600 Subject: [PATCH 6/6] Parametrize --- pandas/tests/indexes/datetimes/test_tools.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index dc6f0f1d34bc2..e1f04d3d4489b 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -2317,6 +2317,8 @@ def test_nullable_integer_to_datetime(): tm.assert_series_equal(ser, ser_copy) -def test_na_to_datetime(nulls_fixture): - result = pd.to_datetime([nulls_fixture]) +@pytest.mark.parametrize("klass", [np.array, list]) +def test_na_to_datetime(nulls_fixture, klass): + result = pd.to_datetime(klass([nulls_fixture])) + assert result[0] is pd.NaT