indexing.pyx 733 B

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