indexing.pyx 778 B

12345678910111213141516171819202122232425262728
  1. cdef class NDFrameIndexerBase:
  2. """
  3. A base class for _NDFrameIndexer for fast instantiation and attribute access.
  4. """
  5. cdef:
  6. Py_ssize_t _ndim
  7. cdef public:
  8. str name
  9. object obj
  10. def __init__(self, name: str, obj):
  11. self.obj = obj
  12. self.name = name
  13. self._ndim = -1
  14. @property
  15. def ndim(self) -> int:
  16. # Delay `ndim` instantiation until required as reading it
  17. # from `obj` isn't entirely cheap.
  18. ndim = self._ndim
  19. if ndim == -1:
  20. ndim = self._ndim = self.obj.ndim
  21. if ndim > 2:
  22. raise ValueError( # pragma: no cover
  23. "NDFrameIndexer does not support NDFrame objects with ndim > 2"
  24. )
  25. return ndim