internals.pyi 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. from typing import (
  2. Iterator,
  3. Sequence,
  4. final,
  5. overload,
  6. )
  7. import weakref
  8. import numpy as np
  9. from pandas._typing import (
  10. ArrayLike,
  11. Self,
  12. npt,
  13. )
  14. from pandas import Index
  15. from pandas.core.internals.blocks import Block as B
  16. def slice_len(slc: slice, objlen: int = ...) -> int: ...
  17. def get_concat_blkno_indexers(
  18. blknos_list: list[npt.NDArray[np.intp]],
  19. ) -> list[tuple[npt.NDArray[np.intp], BlockPlacement]]: ...
  20. def get_blkno_indexers(
  21. blknos: np.ndarray, # int64_t[:]
  22. group: bool = ...,
  23. ) -> list[tuple[int, slice | np.ndarray]]: ...
  24. def get_blkno_placements(
  25. blknos: np.ndarray,
  26. group: bool = ...,
  27. ) -> Iterator[tuple[int, BlockPlacement]]: ...
  28. def update_blklocs_and_blknos(
  29. blklocs: npt.NDArray[np.intp],
  30. blknos: npt.NDArray[np.intp],
  31. loc: int,
  32. nblocks: int,
  33. ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
  34. @final
  35. class BlockPlacement:
  36. def __init__(self, val: int | slice | np.ndarray) -> None: ...
  37. @property
  38. def indexer(self) -> np.ndarray | slice: ...
  39. @property
  40. def as_array(self) -> np.ndarray: ...
  41. @property
  42. def as_slice(self) -> slice: ...
  43. @property
  44. def is_slice_like(self) -> bool: ...
  45. @overload
  46. def __getitem__(
  47. self, loc: slice | Sequence[int] | npt.NDArray[np.intp]
  48. ) -> BlockPlacement: ...
  49. @overload
  50. def __getitem__(self, loc: int) -> int: ...
  51. def __iter__(self) -> Iterator[int]: ...
  52. def __len__(self) -> int: ...
  53. def delete(self, loc) -> BlockPlacement: ...
  54. def add(self, other) -> BlockPlacement: ...
  55. def append(self, others: list[BlockPlacement]) -> BlockPlacement: ...
  56. def tile_for_unstack(self, factor: int) -> npt.NDArray[np.intp]: ...
  57. class Block:
  58. _mgr_locs: BlockPlacement
  59. ndim: int
  60. values: ArrayLike
  61. refs: BlockValuesRefs
  62. def __init__(
  63. self,
  64. values: ArrayLike,
  65. placement: BlockPlacement,
  66. ndim: int,
  67. refs: BlockValuesRefs | None = ...,
  68. ) -> None: ...
  69. def slice_block_rows(self, slicer: slice) -> Self: ...
  70. class BlockManager:
  71. blocks: tuple[B, ...]
  72. axes: list[Index]
  73. _known_consolidated: bool
  74. _is_consolidated: bool
  75. _blknos: np.ndarray
  76. _blklocs: np.ndarray
  77. def __init__(
  78. self, blocks: tuple[B, ...], axes: list[Index], verify_integrity=...
  79. ) -> None: ...
  80. def get_slice(self, slobj: slice, axis: int = ...) -> Self: ...
  81. def _rebuild_blknos_and_blklocs(self) -> None: ...
  82. class BlockValuesRefs:
  83. referenced_blocks: list[weakref.ref]
  84. def __init__(self, blk: Block | None = ...) -> None: ...
  85. def add_reference(self, blk: Block) -> None: ...
  86. def add_index_reference(self, index: Index) -> None: ...
  87. def has_reference(self) -> bool: ...