Skip to content

Commit 881e076

Browse files
committed
fix 4ea83c7
1 parent 2278081 commit 881e076

File tree

2 files changed

+448
-59
lines changed

2 files changed

+448
-59
lines changed

pandas-stubs/_typing.pyi

Lines changed: 87 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ BuiltinFloatDtypeArg: TypeAlias = type[float] | Literal["float"]
317317
PandasFloatDtypeArg: TypeAlias = (
318318
pd.Float32Dtype | pd.Float64Dtype | Literal["Float32", "Float64"]
319319
)
320+
PandasAstypeFloatDtypeArg: TypeAlias = (
321+
Literal["float_"] # noqa: PYI030
322+
| Literal["f16", "float128", "longdouble", "longfloat"]
323+
)
320324
# Numpy float types and their string aliases
321325
NumpyFloatDtypeArg: TypeAlias = (
322326
# NOTE: Alias np.float16 only on Linux x86_64, use np.half instead
@@ -328,10 +332,10 @@ NumpyFloatDtypeArg: TypeAlias = (
328332
| Literal["f", "f4", "float32", "single"]
329333
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.double
330334
| type[np.double]
331-
| Literal["d", "f8", "float64", "double", "float_"]
335+
| Literal["d", "f8", "float64", "double"]
332336
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.longdouble
333337
| type[np.longdouble]
334-
| Literal["g", "f16", "float128", "longdouble", "longfloat"]
338+
| Literal["g"] # "float128"
335339
)
336340
# PyArrow floating point types and their string aliases
337341
PyArrowFloatDtypeArg: TypeAlias = Literal[
@@ -344,38 +348,41 @@ PyArrowFloatDtypeArg: TypeAlias = Literal[
344348
FloatDtypeArg: TypeAlias = (
345349
BuiltinFloatDtypeArg
346350
| PandasFloatDtypeArg
351+
| PandasAstypeFloatDtypeArg
347352
| NumpyFloatDtypeArg
348353
| PyArrowFloatDtypeArg
349354
)
350355
# Builtin complex type and its string alias
351356
BuiltinComplexDtypeArg: TypeAlias = type[complex] | Literal["complex"]
357+
PandasAstypeComplexDtypeArg: TypeAlias = (
358+
Literal["singlecomplex"] # noqa: PYI030
359+
| Literal["cfloat", "complex_"]
360+
| Literal["c32", "complex256", "clongfloat", "longcomplex"]
361+
)
352362
# Numpy complex types and their aliases
353363
NumpyComplexDtypeArg: TypeAlias = (
354364
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.csingle
355365
type[np.csingle] # noqa: PYI030
356-
| Literal["F", "c8", "complex64", "csingle", "singlecomplex"]
366+
| Literal["F", "c8", "complex64", "csingle"]
357367
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.cdouble
358368
| type[np.cdouble]
359-
| Literal["D", "c16", "complex128", "cdouble", "cfloat", "complex_"]
369+
| Literal["D", "c16", "complex128", "cdouble"]
360370
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.clongdouble
361371
# NOTE: Alias np.complex256 only on Linux x86_64, use np.clongdouble instead
362372
| type[np.clongdouble]
363-
| Literal["G", "c32", "complex256", "clongdouble", "clongfloat", "longcomplex"]
373+
| Literal["G", "clongdouble"]
364374
)
365-
ComplexDtypeArg: TypeAlias = BuiltinComplexDtypeArg | NumpyComplexDtypeArg
366-
# Refer to https://numpy.org/doc/stable/reference/arrays.datetime.html#datetime-units
367-
NumpyTimedeltaDtypeArg: TypeAlias = Literal[
375+
ComplexDtypeArg: TypeAlias = (
376+
BuiltinComplexDtypeArg | PandasAstypeComplexDtypeArg | NumpyComplexDtypeArg
377+
)
378+
PandasAstypeTimedeltaDtypeArg: TypeAlias = Literal[
368379
"timedelta64[Y]",
369380
"timedelta64[M]",
370381
"timedelta64[W]",
371382
"timedelta64[D]",
372383
"timedelta64[h]",
373384
"timedelta64[m]",
374-
"timedelta64[s]",
375-
"timedelta64[ms]",
376-
"timedelta64[us]",
377385
"timedelta64[μs]",
378-
"timedelta64[ns]",
379386
"timedelta64[ps]",
380387
"timedelta64[fs]",
381388
"timedelta64[as]",
@@ -386,11 +393,7 @@ NumpyTimedeltaDtypeArg: TypeAlias = Literal[
386393
"m8[D]",
387394
"m8[h]",
388395
"m8[m]",
389-
"m8[s]",
390-
"m8[ms]",
391-
"m8[us]",
392396
"m8[μs]",
393-
"m8[ns]",
394397
"m8[ps]",
395398
"m8[fs]",
396399
"m8[as]",
@@ -401,50 +404,69 @@ NumpyTimedeltaDtypeArg: TypeAlias = Literal[
401404
"<m8[D]",
402405
"<m8[h]",
403406
"<m8[m]",
404-
"<m8[s]",
405-
"<m8[ms]",
406-
"<m8[us]",
407407
"<m8[μs]",
408-
"<m8[ns]",
409408
"<m8[ps]",
410409
"<m8[fs]",
411410
"<m8[as]",
412411
]
412+
# Refer to https://numpy.org/doc/stable/reference/arrays.datetime.html#datetime-units
413+
NumpyTimedeltaDtypeArg: TypeAlias = Literal[
414+
"timedelta64[s]",
415+
"timedelta64[ms]",
416+
"timedelta64[us]",
417+
"timedelta64[ns]",
418+
# numpy type codes
419+
"m8[s]",
420+
"m8[ms]",
421+
"m8[us]",
422+
"m8[ns]",
423+
# little endian
424+
"<m8[s]",
425+
"<m8[ms]",
426+
"<m8[us]",
427+
"<m8[ns]",
428+
]
413429
# PyArrow duration type and its string alias
414430
PyArrowTimedeltaDtypeArg: TypeAlias = Literal[
415431
"duration[s][pyarrow]",
416432
"duration[ms][pyarrow]",
417433
"duration[us][pyarrow]",
418434
"duration[ns][pyarrow]",
419435
]
420-
TimedeltaDtypeArg: TypeAlias = NumpyTimedeltaDtypeArg | PyArrowTimedeltaDtypeArg
421-
NumpyTimestampDtypeArg: TypeAlias = Literal[
436+
TimedeltaDtypeArg: TypeAlias = (
437+
PandasAstypeTimedeltaDtypeArg | NumpyTimedeltaDtypeArg | PyArrowTimedeltaDtypeArg
438+
)
439+
# Pandas timestamp type and its string alias
440+
# Not comprehensive
441+
PandasTimestampDtypeArg: TypeAlias = (
442+
pd.DatetimeTZDtype
443+
| Literal[
444+
"datetime64[s, UTC]",
445+
"datetime64[ms, UTC]",
446+
"datetime64[us, UTC]",
447+
"datetime64[ns, UTC]",
448+
]
449+
)
450+
PandasAstypeTimestampDtypeArg: TypeAlias = Literal[
451+
# numpy datetime64
422452
"datetime64[Y]",
423453
"datetime64[M]",
424454
"datetime64[W]",
425455
"datetime64[D]",
426456
"datetime64[h]",
427457
"datetime64[m]",
428-
"datetime64[s]",
429-
"datetime64[ms]",
430-
"datetime64[us]",
431458
"datetime64[μs]",
432-
"datetime64[ns]",
433459
"datetime64[ps]",
434460
"datetime64[fs]",
435461
"datetime64[as]",
436-
# numpy type codes
462+
# numpy datetime64 type codes
437463
"M8[Y]",
438464
"M8[M]",
439465
"M8[W]",
440466
"M8[D]",
441467
"M8[h]",
442468
"M8[m]",
443-
"M8[s]",
444-
"M8[ms]",
445-
"M8[us]",
446469
"M8[μs]",
447-
"M8[ns]",
448470
"M8[ps]",
449471
"M8[fs]",
450472
"M8[as]",
@@ -455,26 +477,28 @@ NumpyTimestampDtypeArg: TypeAlias = Literal[
455477
"<M8[D]",
456478
"<M8[h]",
457479
"<M8[m]",
458-
"<M8[s]",
459-
"<M8[ms]",
460-
"<M8[us]",
461480
"<M8[μs]",
462-
"<M8[ns]",
463481
"<M8[ps]",
464482
"<M8[fs]",
465483
"<M8[as]",
466484
]
467-
# Pandas timestamp type and its string alias
468-
# Not comprehensive
469-
PandasTimestampDtypeArg: TypeAlias = (
470-
pd.DatetimeTZDtype
471-
| Literal[
472-
"datetime64[s, UTC]",
473-
"datetime64[ms, UTC]",
474-
"datetime64[us, UTC]",
475-
"datetime64[ns, UTC]",
476-
]
477-
)
485+
# Numpy timestamp type and its string alias
486+
NumpyTimestampDtypeArg: TypeAlias = Literal[
487+
"datetime64[s]",
488+
"datetime64[ms]",
489+
"datetime64[us]",
490+
"datetime64[ns]",
491+
# numpy type codes
492+
"M8[s]",
493+
"M8[ms]",
494+
"M8[us]",
495+
"M8[ns]",
496+
# little endian
497+
"<M8[s]",
498+
"<M8[ms]",
499+
"<M8[us]",
500+
"<M8[ns]",
501+
]
478502
# PyArrow timestamp type and its string alias
479503
PyArrowTimestampDtypeArg: TypeAlias = Literal[
480504
"date32[pyarrow]",
@@ -485,17 +509,18 @@ PyArrowTimestampDtypeArg: TypeAlias = Literal[
485509
"timestamp[ns][pyarrow]",
486510
]
487511
TimestampDtypeArg: TypeAlias = (
488-
PandasTimestampDtypeArg | NumpyTimestampDtypeArg | PyArrowTimestampDtypeArg
512+
PandasTimestampDtypeArg
513+
| PandasAstypeTimestampDtypeArg
514+
| NumpyTimestampDtypeArg
515+
| PyArrowTimestampDtypeArg
489516
)
490517
# Builtin str type and its string alias
491518
BuiltinStrDtypeArg: TypeAlias = type[str] | Literal["str"]
492519
# Pandas nullable string type and its string alias
493520
PandasStrDtypeArg: TypeAlias = pd.StringDtype | Literal["string"]
494521
# Numpy string type and its string alias
495522
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.str_
496-
NumpyStrDtypeArg: TypeAlias = (
497-
type[np.str_] | Literal["U", "str_", "str0", "unicode", "unicode_"]
498-
)
523+
NumpyStrDtypeArg: TypeAlias = type[np.str_] | Literal["U", "str_", "unicode"]
499524
# PyArrow string type and its string alias
500525
PyArrowStrDtypeArg: TypeAlias = Literal["string[pyarrow]"]
501526
StrDtypeArg: TypeAlias = (
@@ -505,9 +530,7 @@ StrDtypeArg: TypeAlias = (
505530
BuiltinBytesDtypeArg: TypeAlias = type[bytes] | Literal["bytes"]
506531
# Numpy bytes type and its string alias
507532
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.bytes_
508-
NumpyBytesDtypeArg: TypeAlias = (
509-
type[np.bytes_] | Literal["S", "bytes_", "bytes0", "string_"]
510-
)
533+
NumpyBytesDtypeArg: TypeAlias = type[np.bytes_] | Literal["S", "bytes_"]
511534
# PyArrow binary type and its string alias
512535
PyArrowBytesDtypeArg: TypeAlias = Literal["binary[pyarrow]"]
513536
BytesDtypeArg: TypeAlias = (
@@ -526,7 +549,7 @@ ObjectDtypeArg: TypeAlias = BuiltinObjectDtypeArg | NumpyObjectDtypeArg
526549

527550
# Numpy void type and its string alias
528551
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.void
529-
NumpyVoidDtypeArg: TypeAlias = type[np.void] | Literal["V", "void", "void0"]
552+
NumpyVoidDtypeArg: TypeAlias = type[np.void] | Literal["V", "void"]
530553
VoidDtypeArg: TypeAlias = NumpyVoidDtypeArg
531554

532555
# DtypeArg specifies all allowable dtypes in a functions its dtype argument
@@ -859,14 +882,21 @@ SliceType: TypeAlias = Hashable | None
859882
## All types below this point are only used in pandas-stubs
860883
######
861884

862-
NumpyDtypeArg: TypeAlias = (
885+
BuiltinDtypeArg: TypeAlias = (
886+
BuiltinBooleanDtypeArg
887+
| BuiltinIntDtypeArg
888+
| BuiltinFloatDtypeArg
889+
| BuiltinComplexDtypeArg
890+
| BuiltinStrDtypeArg
891+
| BuiltinBytesDtypeArg
892+
| BuiltinObjectDtypeArg
893+
)
894+
NumpyNotTimeDtypeArg: TypeAlias = (
863895
NumpyBooleanDtypeArg
864896
| NumpyIntDtypeArg
865897
| NumpyUIntDtypeArg
866898
| NumpyFloatDtypeArg
867899
| NumpyComplexDtypeArg
868-
| NumpyTimedeltaDtypeArg
869-
| NumpyTimestampDtypeArg
870900
| NumpyStrDtypeArg
871901
| NumpyBytesDtypeArg
872902
| NumpyObjectDtypeArg

0 commit comments

Comments
 (0)