Skip to content

Commit bfe5be0

Browse files
authored
REF: Defer creating Index._engine until needed (#58370)
1 parent 0cafd10 commit bfe5be0

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pandas/core/frame.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4012,7 +4012,6 @@ def _get_value(self, index, col, takeable: bool = False) -> Scalar:
40124012
return series._values[index]
40134013

40144014
series = self._get_item(col)
4015-
engine = self.index._engine
40164015

40174016
if not isinstance(self.index, MultiIndex):
40184017
# CategoricalIndex: Trying to use the engine fastpath may give incorrect
@@ -4023,7 +4022,7 @@ def _get_value(self, index, col, takeable: bool = False) -> Scalar:
40234022

40244023
# For MultiIndex going through engine effectively restricts us to
40254024
# same-length tuples; see test_get_set_value_no_partial_indexing
4026-
loc = engine.get_loc(index)
4025+
loc = self.index._engine.get_loc(index)
40274026
return series._values[loc]
40284027

40294028
def isetitem(self, loc, value) -> None:

pandas/core/indexes/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,8 @@ def _reset_identity(self) -> None:
832832

833833
@final
834834
def _cleanup(self) -> None:
835-
self._engine.clear_mapping()
835+
if "_engine" in self._cache:
836+
self._engine.clear_mapping()
836837

837838
@cache_readonly
838839
def _engine(

0 commit comments

Comments
 (0)