1
+ from __future__ import annotations
2
+
1
3
import datetime as dt
2
4
from typing import (
5
+ TYPE_CHECKING ,
3
6
Any ,
4
- Optional ,
5
7
Sequence ,
6
- Tuple ,
7
- Union ,
8
8
cast ,
9
9
)
10
10
11
11
import numpy as np
12
12
13
- from pandas ._typing import (
14
- Dtype ,
15
- PositionalIndexer ,
16
- )
17
-
18
13
from pandas .core .dtypes .dtypes import register_extension_dtype
19
14
20
15
from pandas .api .extensions import (
23
18
)
24
19
from pandas .api .types import pandas_dtype
25
20
21
+ if TYPE_CHECKING :
22
+ from pandas ._typing import (
23
+ Dtype ,
24
+ PositionalIndexer ,
25
+ )
26
+
26
27
27
28
@register_extension_dtype
28
29
class DateDtype (ExtensionDtype ):
@@ -61,12 +62,12 @@ def __repr__(self) -> str:
61
62
class DateArray (ExtensionArray ):
62
63
def __init__ (
63
64
self ,
64
- dates : Union [
65
- dt .date ,
66
- Sequence [dt .date ],
67
- Tuple [np .ndarray , np .ndarray , np .ndarray ],
68
- np .ndarray ,
69
- ] ,
65
+ dates : (
66
+ dt .date
67
+ | Sequence [dt .date ]
68
+ | tuple [np .ndarray , np .ndarray , np .ndarray ]
69
+ | np .ndarray
70
+ ) ,
70
71
) -> None :
71
72
if isinstance (dates , dt .date ):
72
73
self ._year = np .array ([dates .year ])
@@ -146,7 +147,7 @@ def __getitem__(self, item: PositionalIndexer):
146
147
else :
147
148
raise NotImplementedError ("only ints are supported as indexes" )
148
149
149
- def __setitem__ (self , key : Union [ int , slice , np .ndarray ] , value : Any ):
150
+ def __setitem__ (self , key : int | slice | np .ndarray , value : Any ):
150
151
if not isinstance (key , int ):
151
152
raise NotImplementedError ("only ints are supported as indexes" )
152
153
@@ -160,7 +161,7 @@ def __setitem__(self, key: Union[int, slice, np.ndarray], value: Any):
160
161
def __repr__ (self ) -> str :
161
162
return f"DateArray{ list (zip (self ._year , self ._month , self ._day ))} "
162
163
163
- def copy (self ) -> " DateArray" :
164
+ def copy (self ) -> DateArray :
164
165
return DateArray ((self ._year .copy (), self ._month .copy (), self ._day .copy ()))
165
166
166
167
def isna (self ) -> np .ndarray :
@@ -172,7 +173,7 @@ def isna(self) -> np.ndarray:
172
173
)
173
174
174
175
@classmethod
175
- def _from_sequence (cls , scalars , * , dtype : Optional [ Dtype ] = None , copy = False ):
176
+ def _from_sequence (cls , scalars , * , dtype : Dtype | None = None , copy = False ):
176
177
if isinstance (scalars , dt .date ):
177
178
pass
178
179
elif isinstance (scalars , DateArray ):
0 commit comments