@@ -78,6 +78,17 @@ NpDtype: TypeAlias = str | np.dtype[np.generic] | type[str | complex | bool | ob
78
78
Dtype : TypeAlias = ExtensionDtype | NpDtype
79
79
DtypeArg : TypeAlias = Dtype | Mapping [Any , Dtype ]
80
80
DtypeBackend : TypeAlias = Literal ["pyarrow" , "numpy_nullable" ]
81
+
82
+ # NOTE: we want to catch all the possible dtypes from np.sctypeDict
83
+ # timedelta64
84
+ # M
85
+ # m8
86
+ # M8
87
+ # object_
88
+ # object0
89
+ # m
90
+ # datetime64
91
+
81
92
BooleanDtypeArg : TypeAlias = (
82
93
# Builtin bool type and its string alias
83
94
type [bool ] # noqa: Y030
@@ -86,7 +97,11 @@ BooleanDtypeArg: TypeAlias = (
86
97
| pd .BooleanDtype
87
98
| Literal ["boolean" ]
88
99
# Numpy bool type
100
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.bool_
89
101
| type [np .bool_ ]
102
+ | Literal ["?" , "b1" , "bool8" , "bool_" ]
103
+ # PyArrow boolean type and its string alias
104
+ | Literal ["bool[pyarrow]" , "boolean[pyarrow]" ]
90
105
)
91
106
IntDtypeArg : TypeAlias = (
92
107
# Builtin integer type and its string alias
@@ -99,31 +114,56 @@ IntDtypeArg: TypeAlias = (
99
114
| pd .Int64Dtype
100
115
| Literal ["Int8" , "Int16" , "Int32" , "Int64" ]
101
116
# Numpy signed integer types and their string aliases
117
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.byte
102
118
| type [np .byte ]
103
- | type [np .int8 ]
104
- | type [np .int16 ]
105
- | type [np .int32 ]
106
- | type [np .int64 ]
107
- | type [np .intp ]
108
- | Literal ["byte" , "int8" , "int16" , "int32" , "int64" , "intp" ]
119
+ | Literal ["b" , "i1" , "int8" , "byte" ]
120
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.short
121
+ | type [np .short ]
122
+ | Literal ["h" , "i2" , "int16" , "short" ]
123
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.intc
124
+ | type [np .intc ]
125
+ | Literal ["i" , "i4" , "int32" , "intc" ]
126
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.int_
127
+ | type [np .int_ ]
128
+ | Literal ["l" , "i8" , "int64" , "int_" , "long" ]
129
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.longlong
130
+ | type [np .longlong ]
131
+ | Literal ["q" , "longlong" ] # NOTE: int128 not assigned
132
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.intp
133
+ | type [np .intp ] # signed pointer (=`intptr_t`, platform dependent)
134
+ | Literal ["p" , "intp" , "int0" ]
135
+ # PyArrow integer types and their string aliases
136
+ | Literal ["int8[pyarrow]" , "int16[pyarrow]" , "int32[pyarrow]" , "int64[pyarrow]" ]
137
+ )
138
+ UIntDtypeArg : TypeAlias = (
139
+ # Pandas nullable unsigned integer types and their string aliases
140
+ pd .UInt8Dtype # noqa: Y030
141
+ | pd .UInt16Dtype
142
+ | pd .UInt32Dtype
143
+ | pd .UInt64Dtype
144
+ | Literal ["UInt8" , "UInt16" , "UInt32" , "UInt64" ]
109
145
# Numpy unsigned integer types and their string aliases
146
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.ubyte
110
147
| type [np .ubyte ]
111
- | type [np .uint8 ]
112
- | type [np .uint16 ]
113
- | type [np .uint32 ]
114
- | type [np .uint64 ]
115
- | type [np .uintp ]
116
- | Literal ["ubyte" , "uint8" , "uint16" , "uint32" , "uint64" , "uintp" ]
148
+ | Literal ["B" , "u1" , "uint8" , "ubyte" ]
149
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.ushort
150
+ | type [np .ushort ]
151
+ | Literal ["H" , "u2" , "uint16" , "ushort" ]
152
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.uintc
153
+ | type [np .uintc ]
154
+ | Literal ["I" , "u4" , "uint32" , "uintc" ]
155
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.uint
156
+ | type [np .uint ]
157
+ | Literal ["L" , "u8" , "uint" , "ulong" , "uint64" ]
158
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.ulonglong
159
+ | type [np .ulonglong ]
160
+ | Literal ["Q" , "ulonglong" ] # NOTE: uint128 not assigned
161
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.uintp
162
+ | type [np .uintp ] # unsigned pointer (=`uintptr_t`, platform dependent)
163
+ | Literal ["P" , "uintp" , "uint0" ]
164
+ # PyArrow unsigned integer types and their string aliases
165
+ | Literal ["uint8[pyarrow]" , "uint16[pyarrow]" , "uint32[pyarrow]" , "uint64[pyarrow]" ]
117
166
)
118
- StrDtypeArg : TypeAlias = (
119
- # Builtin str type and its string alias
120
- type [str ] # noqa: Y030
121
- | Literal ["str" ]
122
- # Pandas nullable string type and its string alias
123
- | pd .StringDtype
124
- | Literal ["string" ]
125
- )
126
- BytesDtypeArg : TypeAlias = type [bytes ]
127
167
FloatDtypeArg : TypeAlias = (
128
168
# Builtin float type and its string alias
129
169
type [float ] # noqa: Y030
@@ -133,19 +173,50 @@ FloatDtypeArg: TypeAlias = (
133
173
| pd .Float64Dtype
134
174
| Literal ["Float32" , "Float64" ]
135
175
# Numpy float types and their string aliases
136
- | type [np .float16 ]
137
- | type [np .float32 ]
138
- | type [np .float64 ]
139
- | Literal ["float16" , "float32" , "float64" ]
176
+ # NOTE: Alias np.float16 only on Linux x86_64, use np.half instead
177
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.half
178
+ | type [np .half ]
179
+ | Literal ["e" , "f2" , "<f2" , "float16" , "half" ]
180
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.single
181
+ | type [np .single ]
182
+ | Literal ["f" , "f4" , "float32" , "single" ]
183
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.double
184
+ | type [np .double ]
185
+ | Literal ["d" , "f8" , "float64" , "double" , "float_" ]
186
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.longdouble
187
+ | type [np .longdouble ]
188
+ | Literal ["g" , "f16" , "float128" , "longdouble" , "longfloat" ]
189
+ # PyArrow floating point types and their string aliases
190
+ | Literal [
191
+ "float[pyarrow]" ,
192
+ "double[pyarrow]" ,
193
+ "float16[pyarrow]" ,
194
+ "float32[pyarrow]" ,
195
+ "float64[pyarrow]" ,
196
+ ]
140
197
)
141
198
ComplexDtypeArg : TypeAlias = (
142
199
# Builtin complex type and its string alias
143
200
type [complex ] # noqa: Y030
144
201
| Literal ["complex" ]
145
202
# Numpy complex types and their aliases
146
- | type [np .complex64 ]
147
- | type [np .complex128 ]
148
- | Literal ["complex64" , "complex128" ]
203
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.csingle
204
+ | type [np .csingle ]
205
+ | Literal ["F" , "c8" , "complex64" , "csingle" , "singlecomplex" ]
206
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.cdouble
207
+ | type [np .cdouble ]
208
+ | Literal ["D" , "c16" , "complex128" , "cdouble" , "cfloat" , "complex_" ]
209
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.clongdouble
210
+ # NOTE: Alias np.complex256 only on Linux x86_64, use np.clongdouble instead
211
+ | type [np .clongdouble ]
212
+ | Literal [
213
+ "G" ,
214
+ "c32" ,
215
+ "complex256" ,
216
+ "clongdouble" ,
217
+ "clongfloat" ,
218
+ "longcomplex" ,
219
+ ]
149
220
)
150
221
# Refer to https://numpy.org/doc/stable/reference/arrays.datetime.html#datetime-units
151
222
TimedeltaDtypeArg : TypeAlias = Literal [
@@ -163,6 +234,41 @@ TimedeltaDtypeArg: TypeAlias = Literal[
163
234
"timedelta64[ps]" ,
164
235
"timedelta64[fs]" ,
165
236
"timedelta64[as]" ,
237
+ # numpy type codes
238
+ "m8[Y]" ,
239
+ "m8[M]" ,
240
+ "m8[W]" ,
241
+ "m8[D]" ,
242
+ "m8[h]" ,
243
+ "m8[m]" ,
244
+ "m8[s]" ,
245
+ "m8[ms]" ,
246
+ "m8[us]" ,
247
+ "m8[μs]" ,
248
+ "m8[ns]" ,
249
+ "m8[ps]" ,
250
+ "m8[fs]" ,
251
+ "m8[as]" ,
252
+ # little endian
253
+ "<m8[Y]" ,
254
+ "<m8[M]" ,
255
+ "<m8[W]" ,
256
+ "<m8[D]" ,
257
+ "<m8[h]" ,
258
+ "<m8[m]" ,
259
+ "<m8[s]" ,
260
+ "<m8[ms]" ,
261
+ "<m8[us]" ,
262
+ "<m8[μs]" ,
263
+ "<m8[ns]" ,
264
+ "<m8[ps]" ,
265
+ "<m8[fs]" ,
266
+ "<m8[as]" ,
267
+ # PyArrow duration type and its string alias
268
+ "duration[s][pyarrow]" ,
269
+ "duration[ms][pyarrow]" ,
270
+ "duration[us][pyarrow]" ,
271
+ "duration[ns][pyarrow]" ,
166
272
]
167
273
TimestampDtypeArg : TypeAlias = Literal [
168
274
"datetime64[Y]" ,
@@ -179,24 +285,107 @@ TimestampDtypeArg: TypeAlias = Literal[
179
285
"datetime64[ps]" ,
180
286
"datetime64[fs]" ,
181
287
"datetime64[as]" ,
288
+ # numpy type codes
289
+ "M8[Y]" ,
290
+ "M8[M]" ,
291
+ "M8[W]" ,
292
+ "M8[D]" ,
293
+ "M8[h]" ,
294
+ "M8[m]" ,
295
+ "M8[s]" ,
296
+ "M8[ms]" ,
297
+ "M8[us]" ,
298
+ "M8[μs]" ,
299
+ "M8[ns]" ,
300
+ "M8[ps]" ,
301
+ "M8[fs]" ,
302
+ "M8[as]" ,
303
+ # little endian
304
+ "<M8[Y]" ,
305
+ "<M8[M]" ,
306
+ "<M8[W]" ,
307
+ "<M8[D]" ,
308
+ "<M8[h]" ,
309
+ "<M8[m]" ,
310
+ "<M8[s]" ,
311
+ "<M8[ms]" ,
312
+ "<M8[us]" ,
313
+ "<M8[μs]" ,
314
+ "<M8[ns]" ,
315
+ "<M8[ps]" ,
316
+ "<M8[fs]" ,
317
+ "<M8[as]" ,
318
+ # PyArrow timestamp type and its string alias
319
+ "date32[pyarrow]" ,
320
+ "date64[pyarrow]" ,
321
+ "timestamp[s][pyarrow]" ,
322
+ "timestamp[ms][pyarrow]" ,
323
+ "timestamp[us][pyarrow]" ,
324
+ "timestamp[ns][pyarrow]" ,
182
325
]
326
+
327
+ StrDtypeArg : TypeAlias = (
328
+ # Builtin str type and its string alias
329
+ type [str ] # noqa: Y030
330
+ | Literal ["str" ]
331
+ # Pandas nullable string type and its string alias
332
+ | pd .StringDtype
333
+ | Literal ["string" ]
334
+ # Numpy string type and its string alias
335
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.str_
336
+ | type [np .str_ ]
337
+ | Literal ["U" , "str_" , "str0" , "unicode" , "unicode_" ]
338
+ # PyArrow string type and its string alias
339
+ | Literal ["string[pyarrow]" ]
340
+ )
341
+ BytesDtypeArg : TypeAlias = (
342
+ # Builtin bytes type and its string alias
343
+ type [bytes ] # noqa: Y030
344
+ | Literal ["bytes" ]
345
+ # Numpy bytes type and its string alias
346
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.bytes_
347
+ | type [np .bytes_ ]
348
+ | Literal ["S" , "a" , "bytes_" , "bytes0" , "string_" ]
349
+ # PyArrow binary type and its string alias
350
+ | Literal ["binary[pyarrow]" ]
351
+ )
183
352
CategoryDtypeArg : TypeAlias = CategoricalDtype | Literal ["category" ]
184
353
354
+ ObjectDtypeArg : TypeAlias = (
355
+ # Builtin object type and its string alias
356
+ type [object ] # noqa: Y030
357
+ | Literal ["object" ]
358
+ # Numpy object type and its string alias
359
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.object_
360
+ | type [np .object_ ]
361
+ | Literal ["O" ] # NOTE: "object_" not assigned
362
+ )
363
+
364
+ VoidDtypeArg : TypeAlias = (
365
+ # Numpy void type and its string alias
366
+ # https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.void
367
+ type [np .void ]
368
+ | Literal ["V" , "void" , "void0" ]
369
+ )
370
+
371
+ # DtypeArg specifies all allowable dtypes in a functions its dtype argument
372
+ DtypeObj : TypeAlias = np .dtype [np .generic ] | ExtensionDtype
373
+
185
374
AstypeArg : TypeAlias = (
186
375
BooleanDtypeArg
187
376
| IntDtypeArg
377
+ | UIntDtypeArg
188
378
| StrDtypeArg
189
379
| BytesDtypeArg
190
380
| FloatDtypeArg
191
381
| ComplexDtypeArg
192
382
| TimedeltaDtypeArg
193
383
| TimestampDtypeArg
194
384
| CategoryDtypeArg
195
- | ExtensionDtype
196
- | type [object ]
385
+ | ObjectDtypeArg
386
+ | VoidDtypeArg
387
+ | DtypeObj
197
388
)
198
- # DtypeArg specifies all allowable dtypes in a functions its dtype argument
199
- DtypeObj : TypeAlias = np .dtype [np .generic ] | ExtensionDtype
200
389
201
390
# filenames and file-like-objects
202
391
AnyStr_cov = TypeVar ("AnyStr_cov" , str , bytes , covariant = True )
0 commit comments