_iotools.pyi 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from collections.abc import Callable, Iterable, Sequence
  2. from typing import Any, ClassVar, Final, Literal, TypedDict, overload, type_check_only
  3. from typing_extensions import TypeVar, Unpack
  4. import numpy as np
  5. import numpy.typing as npt
  6. _T = TypeVar("_T")
  7. @type_check_only
  8. class _ValidationKwargs(TypedDict, total=False):
  9. excludelist: Iterable[str] | None
  10. deletechars: Iterable[str] | None
  11. case_sensitive: Literal["upper", "lower"] | bool | None
  12. replace_space: str
  13. ###
  14. __docformat__: Final[str] = "restructuredtext en"
  15. class ConverterError(Exception): ...
  16. class ConverterLockError(ConverterError): ...
  17. class ConversionWarning(UserWarning): ...
  18. class LineSplitter:
  19. delimiter: str | int | Iterable[int] | None
  20. comments: str
  21. encoding: str | None
  22. def __init__(
  23. self,
  24. /,
  25. delimiter: str | bytes | int | Iterable[int] | None = None,
  26. comments: str | bytes = "#",
  27. autostrip: bool = True,
  28. encoding: str | None = None,
  29. ) -> None: ...
  30. def __call__(self, /, line: str | bytes) -> list[str]: ...
  31. def autostrip(self, /, method: Callable[[_T], Iterable[str]]) -> Callable[[_T], list[str]]: ...
  32. class NameValidator:
  33. defaultexcludelist: ClassVar[Sequence[str]]
  34. defaultdeletechars: ClassVar[Sequence[str]]
  35. excludelist: list[str]
  36. deletechars: set[str]
  37. case_converter: Callable[[str], str]
  38. replace_space: str
  39. def __init__(
  40. self,
  41. /,
  42. excludelist: Iterable[str] | None = None,
  43. deletechars: Iterable[str] | None = None,
  44. case_sensitive: Literal["upper", "lower"] | bool | None = None,
  45. replace_space: str = "_",
  46. ) -> None: ...
  47. def __call__(self, /, names: Iterable[str], defaultfmt: str = "f%i", nbfields: int | None = None) -> tuple[str, ...]: ...
  48. def validate(self, /, names: Iterable[str], defaultfmt: str = "f%i", nbfields: int | None = None) -> tuple[str, ...]: ...
  49. class StringConverter:
  50. func: Callable[[str], Any] | None
  51. default: Any
  52. missing_values: set[str]
  53. type: np.dtype[np.datetime64] | np.generic
  54. def __init__(
  55. self,
  56. /,
  57. dtype_or_func: npt.DTypeLike | None = None,
  58. default: None = None,
  59. missing_values: Iterable[str] | None = None,
  60. locked: bool = False,
  61. ) -> None: ...
  62. def update(
  63. self,
  64. /,
  65. func: Callable[[str], Any],
  66. default: object | None = None,
  67. testing_value: str | None = None,
  68. missing_values: str = "",
  69. locked: bool = False,
  70. ) -> None: ...
  71. #
  72. def __call__(self, /, value: str) -> Any: ...
  73. def upgrade(self, /, value: str) -> Any: ...
  74. def iterupgrade(self, /, value: Iterable[str] | str) -> None: ...
  75. #
  76. @classmethod
  77. def upgrade_mapper(cls, func: Callable[[str], Any], default: object | None = None) -> None: ...
  78. @overload
  79. def str2bool(value: Literal["false", "False", "FALSE"]) -> Literal[False]: ...
  80. @overload
  81. def str2bool(value: Literal["true", "True", "TRUE"]) -> Literal[True]: ...
  82. #
  83. def has_nested_fields(ndtype: np.dtype[np.void]) -> bool: ...
  84. def flatten_dtype(ndtype: np.dtype[np.void], flatten_base: bool = False) -> type[np.dtype[Any]]: ...
  85. def easy_dtype(
  86. ndtype: npt.DTypeLike,
  87. names: Iterable[str] | None = None,
  88. defaultfmt: str = "f%i",
  89. **validationargs: Unpack[_ValidationKwargs],
  90. ) -> np.dtype[np.void]: ...