From d2ffa324ccf92e033d2d5f2a2c8f116fc0082297 Mon Sep 17 00:00:00 2001 From: Mark Elliot <123787712+mark-thm@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:53:33 -0500 Subject: [PATCH] Enable construction of pd.Series with NaT and NA (#874) * Enable construction of pd.Series with NaT and NA * cleanup --- pandas-stubs/core/series.pyi | 11 ++++++++++- tests/test_series.py | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 46a8ce14..d38b54da 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -90,6 +90,7 @@ from pandas._libs.interval import ( from pandas._libs.lib import NoDefault from pandas._libs.missing import NAType from pandas._libs.tslibs import BaseOffset +from pandas._libs.tslibs.nattype import NaTType from pandas._typing import ( S1, AggFuncTypeBase, @@ -318,7 +319,15 @@ class Series(IndexOpsMixin[S1], NDFrame): @overload def __new__( cls, - data: Scalar | _ListLike | dict[HashableT1, Any] | BaseGroupBy | None = ..., + data: ( + Scalar + | _ListLike + | dict[HashableT1, Any] + | BaseGroupBy + | NaTType + | NAType + | None + ) = ..., index: Axes | None = ..., *, dtype: Dtype = ..., diff --git a/tests/test_series.py b/tests/test_series.py index c67092fb..8bbe0f8d 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -81,6 +81,8 @@ def test_types_init() -> None: pd.Series(1) pd.Series((1, 2, 3)) pd.Series(np.array([1, 2, 3])) + pd.Series(pd.NaT) + pd.Series(pd.NA) pd.Series(data=[1, 2, 3, 4], name="series") pd.Series(data=[1, 2, 3, 4], dtype=np.int8) pd.Series(data={"row1": [1, 2], "row2": [3, 4]})