summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/__init__.pyi13
-rw-r--r--numpy/typing/tests/data/pass/scalars.py1
2 files changed, 13 insertions, 1 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index 68a14ced6..70f1138d3 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -2537,11 +2537,22 @@ class object_(generic):
object0 = object_
+# The `datetime64` constructors requires an object with the three attributes below,
+# and thus supports datetime duck typing
+class _DatetimeScalar(Protocol):
+ @property
+ def day(self) -> int: ...
+ @property
+ def month(self) -> int: ...
+ @property
+ def year(self) -> int: ...
+
+
class datetime64(generic):
@overload
def __init__(
self,
- __value: Union[None, datetime64, _CharLike_co, dt.datetime] = ...,
+ __value: Union[None, datetime64, _CharLike_co, _DatetimeScalar] = ...,
__format: Union[_CharLike_co, Tuple[_CharLike_co, _IntLike_co]] = ...,
) -> None: ...
@overload
diff --git a/numpy/typing/tests/data/pass/scalars.py b/numpy/typing/tests/data/pass/scalars.py
index c3f4ddbcc..815566b68 100644
--- a/numpy/typing/tests/data/pass/scalars.py
+++ b/numpy/typing/tests/data/pass/scalars.py
@@ -84,6 +84,7 @@ np.datetime64(b"2019")
np.datetime64("2019", "D")
np.datetime64(np.datetime64())
np.datetime64(dt.datetime(2000, 5, 3))
+np.datetime64(dt.date(2000, 5, 3))
np.datetime64(None)
np.datetime64(None, "D")