_scalars.py 1.0 KB

123456789101112131415161718192021222324252627
  1. from typing import Any, TypeAlias
  2. import numpy as np
  3. # NOTE: `_StrLike_co` and `_BytesLike_co` are pointless, as `np.str_` and
  4. # `np.bytes_` are already subclasses of their builtin counterpart
  5. _CharLike_co: TypeAlias = str | bytes
  6. # The 6 `<X>Like_co` type-aliases below represent all scalars that can be
  7. # coerced into `<X>` (with the casting rule `same_kind`)
  8. _BoolLike_co: TypeAlias = bool | np.bool
  9. _UIntLike_co: TypeAlias = np.unsignedinteger[Any] | _BoolLike_co
  10. _IntLike_co: TypeAlias = int | np.integer[Any] | _BoolLike_co
  11. _FloatLike_co: TypeAlias = float | np.floating[Any] | _IntLike_co
  12. _ComplexLike_co: TypeAlias = (
  13. complex
  14. | np.complexfloating[Any, Any]
  15. | _FloatLike_co
  16. )
  17. _TD64Like_co: TypeAlias = np.timedelta64 | _IntLike_co
  18. _NumberLike_co: TypeAlias = int | float | complex | np.number[Any] | np.bool
  19. _ScalarLike_co: TypeAlias = int | float | complex | str | bytes | np.generic
  20. # `_VoidLike_co` is technically not a scalar, but it's close enough
  21. _VoidLike_co: TypeAlias = tuple[Any, ...] | np.void